**************************************************************
**************************************************************
**				  TO POOL ALL C-DEM DATA					**
**           	INFORMAL POL PARTICIPATION 		            **					  
**************************************************************
**************************************************************

***
**************************************************************
**   DATASET : 2019 CANADIAN FEDERAL ELECTION				**
**************************************************************
***



clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"

use "2019 Canadian Election Study - Online Survey v1.0.dta", clear


set more off
numlabel, add



**************************************************************
** 					Generate variables 						**
**************************************************************

*Electoral Participation (0=abstained; 1=voted)
gen turnout=0 if inlist(pes19_turnout2019, 2, 3, 4, 5, 6, 8)
replace turnout=1 if pes19_turnout2019==1

*Age linear
gen age=cps19_age
drop if age < 18

*Gender (0=woman; 1=man; 2=other)
gen gender=0 if cps19_gender==2
replace gender=1 if cps19_gender==1
replace gender=2 if cps19_gender==3

gen gender_dicho=0 if cps19_gender==2 // woman
replace gender_dicho=1 if cps19_gender==1 // man


*Sexuality (0=heterosexual; 1=gay or lesbian; 2=bisexual; 3=other)
gen sexuality=0 if cps19_sexuality==1
replace sexuality=1 if cps19_sexuality==2
replace sexuality=2 if cps19_sexuality==3
replace sexuality=3 if cps19_sexuality==4

gen sexuality_three=sexuality
recode sexuality_three (3=.)

*Education (0=No university; 1=University Degree)
gen education=0 if cps19_education < 9 // No schooling to some university
replace education = 1 if inrange(cps19_education, 9, 11) // Bachelor's degree to Professional degree or doctorate


* Generate the categorical variable from the continuous variable
egen cps19_income_cat_num = cut(cps19_income_number), at(0 1 30001 60001 90001 110001 150001 200001 10000000)
recode cps19_income_cat_num (0 = 1) (1 = 2) (30001 = 3) (60001 = 4) (90001 = 5) (110001 = 6) (150001 = 7) (200001 = 8)

* Replace category '9' in cps21_income_cat with missing
gen income_cat_brut = cps19_income_cat
replace income_cat_brut = . if income_cat_brut == 9

* Merge the two categorical variables
gen income_cat_merged = .
replace income_cat_merged = income_cat_brut if !missing(income_cat_brut)
replace income_cat_merged = cps19_income_cat_num if missing(cps19_income_cat) & !missing(cps19_income_cat_num)

* Create the 0-1 scaled "income" variable
gen income = (income_cat_merged - 1) / 7

*Income (nominal, missing as a category)
gen income_missing = income_cat_merged
replace income_missing = 9 if cps19_income_cat==9

* Initialize the language_cat variable as missing
gen langue_nominal = .

* Anglophone
replace langue_nominal = 1 if !missing(cps19_language_68) & missing(cps19_language_69)

* Francophone
replace langue_nominal = 2 if !missing(cps19_language_69) & missing(cps19_language_68)

* Bilingue FR-EN
replace langue_nominal = 3 if !missing(cps19_language_68) & !missing(cps19_language_69)

* Set minovis to 1 if any of the specified variables are 1
foreach var of varlist cps19_language_70 cps19_language_71 cps19_language_72 cps19_language_73 cps19_language_74 cps19_language_75 cps19_language_76 cps19_language_77 cps19_language_78 cps19_language_79 cps19_language_80 cps19_language_81 cps19_language_82 cps19_language_83 cps19_language_84 {
    replace langue_nominal = 4 if !missing(`var')
}

* Language Binary (FR = 1)
gen franco = .
replace franco = 1 if langue_nominal == 2
replace franco = 0 if langue_nominal == 1 | langue_nominal == 4



* Generate minovis
gen minovis = .
replace minovis = 0 if inlist(cps19_ethnicity_24, 1) | ///
inlist(cps19_ethnicity_26, 1) | ///
inlist(cps19_ethnicity_27, 1) | ///
inlist(cps19_ethnicity_28, 1) | ///
inlist(cps19_ethnicity_29, 1) | ///
inlist(cps19_ethnicity_30, 1) | ///
inlist(cps19_ethnicity_34, 1) | ///
inlist(cps19_ethnicity_35, 1) | ///
inlist(cps19_ethnicity_37, 1) | ///
inlist(cps19_ethnicity_38, 1) | ///
inlist(cps19_ethnicity_39, 1) | ///
inlist(cps19_ethnicity_40, 1)
replace minovis = 1 if minovis == .
replace minovis = . if cps19_ethnicity_43 == 1


* Generate the 'region' variable
gen region = .

* Group provinces into regions and drop the territories
replace region = 1 if cps19_province == 15                         // British Columbia
replace region = 2 if cps19_province == 14 | cps19_province == 16 | cps19_province == 25  // Alberta, Manitoba, Saskatchewan (Prairies)
replace region = 3 if cps19_province == 22                         // Ontario
replace region = 4 if cps19_province == 24                        // Quebec
replace region = 5 if cps19_province == 17 | cps19_province == 18 | cps19_province == 20 | cps19_province == 23 // New Brunswick, Newfoundland and Labrador, Nova Scotia, Prince Edward Island (Atlantic)

drop if cps19_province == 19 | cps19_province == 21 | cps19_province == 26 // Northwest Territories, Nunavut, Yukon

* Generate political interest
gen political_interest = cps19_interest_gen_1
replace political_interest = . if political_interest < 0 | political_interest > 10
replace political_interest = (political_interest - 0) / (10 - 0)

* Generate election_interest
gen election_interest = cps19_interest_elxn_1
replace election_interest = . if election_interest < 0 | election_interest > 10
replace election_interest = (election_interest - 0) / (10 - 0)

* Generate the 'civic_duty' variable
gen civic_duty = .

* Recode cps19_duty_choice values
replace civic_duty = 1 if cps19_duty_choice == 1
replace civic_duty = 0 if cps19_duty_choice == 2
*replace civic_duty = 0.5 if cps19_duty_choice == 3

* Generate the 'rural_urban' variable
gen rural_urban = pes19_rural_urban
replace rural_urban = . if rural_urban == 6

* Generate the string variable 'elecid'
gen elecid = "Canada_2019"


* Gen weights
gen pes_weights = pes19_weight_general_all


*Generate asset variables
gen asset1 = !missing(cps19_property_1)
gen asset2 = !missing(cps19_property_2)
gen asset3 = !missing(cps19_property_3)
gen asset4 = !missing(cps19_property_4)

*Generate index "asset"
gen asset = asset1 + asset2 + asset3 + asset4
replace asset = . if asset == 0
replace asset = 0 if !missing(cps19_property_5)
replace asset = asset / 4

*Gen economic well-being 
gen eco_well_being = (income + asset)/2





*****INFORMAL PARTCIIPATION****
	
* Generate meeting (0-1)
gen meeting = .
replace meeting = 0 if pes19_partic1_1 == 1
replace meeting = 0.33 if pes19_partic1_1 == 2
replace meeting = 0.67 if pes19_partic1_1 == 3	
replace meeting = 1 if pes19_partic1_1 == 4

gen meeting_dicho = .
replace meeting_dicho = 0 if pes19_partic1_1 == 1
replace meeting_dicho = 1 if inlist(pes19_partic1_1, 2, 3, 4)

* Generate protest (0-1)
gen protest = .
replace protest = 0 if pes19_partic1_2 == 1
replace protest = 0.33 if pes19_partic1_2 == 2
replace protest = 0.67 if pes19_partic1_2 == 3	
replace protest = 1 if pes19_partic1_2 == 4

gen protest_dicho = .
replace protest_dicho = 0 if pes19_partic1_2 == 1
replace protest_dicho = 1 if inlist(pes19_partic1_2, 2, 3, 4)

* Generate boycott (0-1)
gen boycott = .
replace boycott = 0 if pes19_partic1_3 == 1
replace boycott = 0.33 if pes19_partic1_3 == 2
replace boycott = 0.67 if pes19_partic1_3 == 3	
replace boycott = 1 if pes19_partic1_3 == 4

gen boycott_dicho = .
replace boycott_dicho = 0 if pes19_partic1_3 == 1
replace boycott_dicho = 1 if inlist(pes19_partic1_3, 2, 3, 4)

* Generate petition (0-1)
gen petition = .
replace petition = 0 if pes19_partic3_6 == 1
replace petition = 0.33 if pes19_partic3_6 == 2
replace petition = 0.67 if pes19_partic3_6 == 3	
replace petition = 1 if pes19_partic3_6 == 4

gen petition_dicho = .
replace petition_dicho = 0 if pes19_partic3_6 == 1
replace petition_dicho = 1 if inlist(pes19_partic3_6, 2, 3, 4)


*****pes19_partic2****


* Generate socialm (0-1)
gen socialm = .
replace socialm = 0 if pes19_partic2_1 == 1
replace socialm = 0.33 if pes19_partic2_1 == 2
replace socialm = 0.67 if pes19_partic2_1 == 3	
replace socialm = 1 if pes19_partic2_1 == 4

gen socialm_dicho = .
replace socialm_dicho = 0 if pes19_partic2_1 == 1
replace socialm_dicho = 1 if inlist(pes19_partic2_1, 2, 3, 4)

* Generate volunteer (0-1)
gen volunteer = .
replace volunteer = 0 if pes19_partic2_2 == 1
replace volunteer = 0.33 if pes19_partic2_2 == 2
replace volunteer = 0.67 if pes19_partic2_2 == 3	
replace volunteer = 1 if pes19_partic2_2 == 4

gen volunteer_dicho = .
replace volunteer_dicho = 0 if pes19_partic2_2 == 1
replace volunteer_dicho = 1 if inlist(pes19_partic2_2, 2, 3, 4)

* Generate contactRep (0-1)
gen contactRep = .
replace contactRep = 0 if pes19_partic2_3 == 1
replace contactRep = 0.33 if pes19_partic2_3 == 2
replace contactRep = 0.67 if pes19_partic2_3 == 3	
replace contactRep = 1 if pes19_partic2_3 == 4

gen contactRep_dicho = .
replace contactRep_dicho = 0 if pes19_partic2_3 == 1
replace contactRep_dicho = 1 if inlist(pes19_partic2_3, 2, 3, 4)

* Generate donate (0-1)
gen donate = .
replace donate = 0 if pes19_partic2_4 == 1
replace donate = 0.33 if pes19_partic2_4 == 2
replace donate = 0.67 if pes19_partic2_4 == 3	
replace donate = 1 if pes19_partic2_4 == 4

gen donate_dicho = .
replace donate_dicho = 0 if pes19_partic2_4 == 1
replace donate_dicho = 1 if inlist(pes19_partic2_4, 2, 3, 4)
		
	
*****pes19_partic3****

* Generate circulatedInfo (0-1)
gen circulatedInfo = .
replace circulatedInfo = 0 if pes19_partic3_4 == 1
replace circulatedInfo = 0.33 if pes19_partic3_4 == 2
replace circulatedInfo = 0.67 if pes19_partic3_4 == 3	
replace circulatedInfo = 1 if pes19_partic3_4 == 4

gen circulatedInfo_dicho = .
replace circulatedInfo_dicho = 0 if pes19_partic3_4 == 1
replace circulatedInfo_dicho = 1 if inlist(pes19_partic3_4, 2, 3, 4)


* Generate usedSocialm (0-1)
gen usedSocialm = .
replace usedSocialm = 0 if pes19_partic3_5 == 1
replace usedSocialm = 0.33 if pes19_partic3_5 == 2
replace usedSocialm = 0.67 if pes19_partic3_5 == 3	
replace usedSocialm = 1 if pes19_partic3_5 == 4

gen usedSocialm_dicho = .
replace usedSocialm_dicho = 0 if pes19_partic3_5 == 1
replace usedSocialm_dicho = 1 if inlist(pes19_partic3_5, 2, 3, 4)
	

*****pes19_partymember****

* Generate member (1 = yes)
gen member = .
replace member = 1 if pes19_partymember == 1
replace member = 0 if inlist(pes19_partymember, 2, 3)



******************
****  KEEP  ******
******************


keep turnout age gender gender_dicho sexuality sexuality_three education income income_cat_merged langue_nominal ///
	franco minovis region political_interest election_interest civic_duty rural_urban elecid meeting meeting_dicho ///
	protest protest_dicho boycott boycott_dicho petition petition_dicho socialm socialm_dicho volunteer volunteer_dicho ///
	contactRep contactRep_dicho donate donate_dicho circulatedInfo circulatedInfo_dicho usedSocialm usedSocialm_dicho ///
	member pes_weights asset eco_well_being income_missing


***************************
********Save
***************************

save "ces2019.dta", replace



***
**************************************************************
**   DATASET : 2021 CANADIAN FEDERAL ELECTION				**
**************************************************************
***


clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"

use "2021 Canadian Election Study v1.0.dta", clear

set more off
numlabel, add







**************************************************************
** 					Generate variables 						**
**************************************************************

*Electoral Participation (0=abstained; 1=voted)
gen turnout=0 if inlist(pes21_turnout2021, 2, 3, 4, 5, 6, 8)
replace turnout=1 if pes21_turnout2021==1

*Age linear
gen age=cps21_age
drop if age < 18

*Gender (0=woman; 1=man; 2=other)
gen gender=0 if cps21_genderid==2
replace gender=1 if cps21_genderid==1
replace gender=2 if cps21_genderid==3
replace gender=2 if cps21_trans==1

gen gender_dicho=0 if cps21_genderid==2 // woman
replace gender_dicho=1 if cps21_genderid==1 // man


*Sexuality (0=heterosexual; 1=gay or lesbian; 2=bisexual; 3=other)
gen sexuality=0 if cps21_sexuality==1
replace sexuality=1 if cps21_sexuality==2
replace sexuality=2 if cps21_sexuality==3
replace sexuality=3 if cps21_sexuality==4
replace sexuality=3 if cps21_sexuality==5

gen sexuality_three=sexuality
recode sexuality_three (3=.)

*Education (0=No university; 1=University Degree)
gen education=0 if cps21_education < 9 // No schooling to some university
replace education = 1 if inrange(cps21_education, 9, 11) // Bachelor's degree to Professional degree or doctorate


* Generate the categorical variable from the continuous variable
egen cps21_income_cat_num = cut(cps21_income_number), at(0 1 30001 60001 90001 110001 150001 200001 10000000)
recode cps21_income_cat_num (0 = 1) (1 = 2) (30001 = 3) (60001 = 4) (90001 = 5) (110001 = 6) (150001 = 7) (200001 = 8)

* Replace category '9' in cps21_income_cat with missing
gen income_cat_brut = cps21_income_cat
replace income_cat_brut = . if income_cat_brut == 9

* Merge the two categorical variables
gen income_cat_merged = .
replace income_cat_merged = income_cat_brut if !missing(income_cat_brut)
replace income_cat_merged = cps21_income_cat_num if missing(cps21_income_cat) & !missing(cps21_income_cat_num)

* Create the 0-1 scaled "income" variable
gen income = (income_cat_merged - 1) / 7

*Income (nominal, missing as a category)
gen income_missing = income_cat_merged
replace income_missing = 9 if cps21_income_cat==9

* Initialize the language_cat variable as missing
gen langue_nominal = .

* Anglophone
replace langue_nominal = 1 if cps21_language_1 == 1 & cps21_language_2 != 1

* Francophone
replace langue_nominal = 2 if cps21_language_2 == 1 & cps21_language_1 != 1

* Bilingue FR-EN
replace langue_nominal = 3 if cps21_language_1 == 1 & cps21_language_2 == 1

* Set to "autre" if any of the specified variables are 1
foreach var of varlist cps21_language_3 cps21_language_5 cps21_language_6 cps21_language_7 cps21_language_8 cps21_language_9 cps21_language_10 cps21_language_11 cps21_language_12 cps21_language_13 cps21_language_14 cps21_language_15 cps21_language_16 cps21_language_17 {
    replace langue_nominal = 4 if `var' == 1
}

* Language Binary (FR = 1)
gen franco = .
replace franco = 1 if langue_nominal == 2
replace franco = 0 if langue_nominal == 1 | langue_nominal == 4


* Generate minovis
gen minovis = .

replace minovis = 0 if cps21_vismin_9 == 1

* Set minovis to 1 if any of the specified variables are 1
foreach var of varlist cps21_vismin_1 cps21_vismin_2 cps21_vismin_3 cps21_vismin_4 cps21_vismin_5 cps21_vismin_6 cps21_vismin_7 cps21_vismin_8 cps21_vismin_10 cps21_vismin_11 {
    replace minovis = 1 if `var' == 1
}

* Set minovis to . (missing in Stata) if cps21_vismin_12 is 1
replace minovis = . if cps21_vismin_12 == 1

* Drop the existing 'province' variable
drop province

* Generate the 'region' variable
gen region = .

* Group provinces into regions and drop the territories
replace region = 1 if cps21_province == 2                         // British Columbia
replace region = 2 if cps21_province == 1 | cps21_province == 3 | cps21_province == 12  // Alberta, Manitoba, Saskatchewan (Prairies)
replace region = 3 if cps21_province == 9                         // Ontario
replace region = 4 if cps21_province == 11                        // Quebec
replace region = 5 if cps21_province == 4 | cps21_province == 5 | cps21_province == 7 | cps21_province == 10 // New Brunswick, Newfoundland and Labrador, Nova Scotia, Prince Edward Island (Atlantic)

drop if cps21_province == 6 | cps21_province == 8 | cps21_province == 13 // Northwest Territories, Nunavut, Yukon


* Generate political interest
gen political_interest = cps21_interest_gen_1
replace political_interest = . if political_interest < 0 | political_interest > 10
replace political_interest = (political_interest - 0) / (10 - 0)

* Generate election_interest
gen election_interest = cps21_interest_elxn_1
replace election_interest = . if election_interest < 0 | election_interest > 10
replace election_interest = (election_interest - 0) / (10 - 0)


* Generate the 'civic_duty' variable
gen civic_duty = .

* Recode cps21_duty_choice values
replace civic_duty = 1 if cps21_duty_choice == 1
replace civic_duty = 0 if cps21_duty_choice == 2
*replace civic_duty = 0.5 if cps21_duty_choice == 3

* Generate the 'rural_urban' variable
gen rural_urban = pes21_rural_urban
replace rural_urban = . if rural_urban == 6

*Generate asset variables
gen asset1 = cps21_property_1 == 1
gen asset2 = cps21_property_2 == 1
gen asset3 = cps21_property_3 == 1
gen asset4 = cps21_property_4 == 1

*Generate index "asset"
gen asset = asset1 + asset2 + asset3 + asset4
replace asset = . if asset == 0
replace asset = 0 if cps21_property_5 == 1
replace asset = asset / 4

*Gen economic well-being 
gen eco_well_being = (income + asset)/2

* Generate the string variable 'elecid'
gen elecid = "Canada_2021"


* Gen weights
gen pes_weights = pes21_weight_general_all

*****INFORMAL PARTCIIPATION****
	
* Generate meeting (0-1)
gen meeting = .
replace meeting = 0 if pes21_partic1_1 == 1
replace meeting = 0.33 if pes21_partic1_1 == 2
replace meeting = 0.67 if pes21_partic1_1 == 3	
replace meeting = 1 if pes21_partic1_1 == 4

gen meeting_dicho = .
replace meeting_dicho = 0 if pes21_partic1_1 == 1
replace meeting_dicho = 1 if inlist(pes21_partic1_1, 2, 3, 4)

* Generate protest (0-1)
gen protest = .
replace protest = 0 if pes21_partic1_2 == 1
replace protest = 0.33 if pes21_partic1_2 == 2
replace protest = 0.67 if pes21_partic1_2 == 3	
replace protest = 1 if pes21_partic1_2 == 4

gen protest_dicho = .
replace protest_dicho = 0 if pes21_partic1_2 == 1
replace protest_dicho = 1 if inlist(pes21_partic1_2, 2, 3, 4)

* Generate boycott (0-1)
gen boycott = .
replace boycott = 0 if pes21_partic1_3 == 1
replace boycott = 0.33 if pes21_partic1_3 == 2
replace boycott = 0.67 if pes21_partic1_3 == 3	
replace boycott = 1 if pes21_partic1_3 == 4

gen boycott_dicho = .
replace boycott_dicho = 0 if pes21_partic1_3 == 1
replace boycott_dicho = 1 if inlist(pes21_partic1_3, 2, 3, 4)

* Generate petition (0-1)
gen petition = .
replace petition = 0 if pes21_partic1_4 == 1
replace petition = 0.33 if pes21_partic1_4 == 2
replace petition = 0.67 if pes21_partic1_4 == 3	
replace petition = 1 if pes21_partic1_4 == 4

gen petition_dicho = .
replace petition_dicho = 0 if pes21_partic1_4 == 1
replace petition_dicho = 1 if inlist(pes21_partic1_4, 2, 3, 4)


*****pes21_partic2****


* Generate socialm (0-1)
gen socialm = .
replace socialm = 0 if pes21_partic2_1 == 1
replace socialm = 0.33 if pes21_partic2_1 == 2
replace socialm = 0.67 if pes21_partic2_1 == 3	
replace socialm = 1 if pes21_partic2_1 == 4

gen socialm_dicho = .
replace socialm_dicho = 0 if pes21_partic2_1 == 1
replace socialm_dicho = 1 if inlist(pes21_partic2_1, 2, 3, 4)

* Generate volunteer (0-1)
gen volunteer = .
replace volunteer = 0 if pes21_partic2_2 == 1
replace volunteer = 0.33 if pes21_partic2_2 == 2
replace volunteer = 0.67 if pes21_partic2_2 == 3	
replace volunteer = 1 if pes21_partic2_2 == 4

gen volunteer_dicho = .
replace volunteer_dicho = 0 if pes21_partic2_2 == 1
replace volunteer_dicho = 1 if inlist(pes21_partic2_2, 2, 3, 4)

* Generate contactRep (0-1)
gen contactRep = .
replace contactRep = 0 if pes21_partic2_3 == 1
replace contactRep = 0.33 if pes21_partic2_3 == 2
replace contactRep = 0.67 if pes21_partic2_3 == 3	
replace contactRep = 1 if pes21_partic2_3 == 4

gen contactRep_dicho = .
replace contactRep_dicho = 0 if pes21_partic2_3 == 1
replace contactRep_dicho = 1 if inlist(pes21_partic2_3, 2, 3, 4)

* Generate donate (0-1)
gen donate = .
replace donate = 0 if pes21_partic2_4 == 1
replace donate = 0.33 if pes21_partic2_4 == 2
replace donate = 0.67 if pes21_partic2_4 == 3	
replace donate = 1 if pes21_partic2_4 == 4

gen donate_dicho = .
replace donate_dicho = 0 if pes21_partic2_4 == 1
replace donate_dicho = 1 if inlist(pes21_partic2_4, 2, 3, 4)	
	
*****pes21_partic3****

* Generate circulatedInfo (0-1)
gen circulatedInfo = .
replace circulatedInfo = 0 if pes21_partic3_3 == 1
replace circulatedInfo = 0.33 if pes21_partic3_3 == 2
replace circulatedInfo = 0.67 if pes21_partic3_3 == 3	
replace circulatedInfo = 1 if pes21_partic3_3 == 4

gen circulatedInfo_dicho = .
replace circulatedInfo_dicho = 0 if pes21_partic3_3 == 1
replace circulatedInfo_dicho = 1 if inlist(pes21_partic3_3, 2, 3, 4)

* Generate usedSocialm (0-1)
gen usedSocialm = .
replace usedSocialm = 0 if pes21_partic3_4 == 1
replace usedSocialm = 0.33 if pes21_partic3_4 == 2
replace usedSocialm = 0.67 if pes21_partic3_4 == 3	
replace usedSocialm = 1 if pes21_partic3_4 == 4
	
gen usedSocialm_dicho = .
replace usedSocialm_dicho = 0 if pes21_partic3_4 == 1
replace usedSocialm_dicho = 1 if inlist(pes21_partic3_4, 2, 3, 4)

*****pes21_partymember****

* Generate member (1 = yes)
gen member = .
replace member = 1 if pes21_partymember == 1
replace member = 0 if inlist(pes21_partymember, 2, 3)



******************
****  KEEP  ******
******************

keep turnout age gender gender_dicho sexuality sexuality_three education income income_cat_merged langue_nominal ///
	franco minovis region political_interest election_interest civic_duty rural_urban elecid meeting meeting_dicho ///
	protest protest_dicho boycott boycott_dicho petition petition_dicho socialm socialm_dicho volunteer volunteer_dicho ///
	contactRep contactRep_dicho donate donate_dicho circulatedInfo circulatedInfo_dicho usedSocialm usedSocialm_dicho ///
	member pes_weights asset eco_well_being income_missing


***************************
********Save
***************************

save "ces2021.dta", replace





***
**************************************************************
**   DATASET : BC 2020 ELECTION								**
**************************************************************
***

clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"

use "BC 2020_Election_Public_Release_Final.dta", clear


set more off
numlabel, add


**************************************************************
** 					Generate variables 						**
**************************************************************

*Electoral Participation (0=abstained; 1=voted)
gen turnout=0 if inlist(pes_turnout, 2, 3, 4, 5, 6)
replace turnout=1 if pes_turnout==1

**********
**Bloc 1**
**********

*Age linear
gen age=cps_age_in_years
drop if age < 18

*Gender (0=woman; 1=man; 2=other)
gen gender=0 if cps_gender==2
replace gender=1 if cps_gender==1
replace gender=2 if cps_gender==3

gen gender_dicho=0 if cps_gender==2 // woman
replace gender_dicho=1 if cps_gender==1 // man


*Sexuality (0=heterosexual; 1=gay or lesbian; 2=bisexual; 3=other)
gen sexuality=0 if pes_orientation==1
replace sexuality=1 if pes_orientation==2
replace sexuality=2 if pes_orientation==3
replace sexuality=3 if pes_orientation==4

gen sexuality_three=sexuality
recode sexuality_three (3=.)

*Education (0=No university; 1=University Degree)
gen education=0 if cps_edu < 9 // No schooling to some university
replace education = 1 if inrange(cps_edu, 9, 11) // Bachelor's degree to Professional degree or doctorate

* Generate the categorical variable from the continuous variable
egen cps_income_cat_num = cut(pes_income), at(0 1 30001 60001 90001 110001 150001 200001 10000000)
recode cps_income_cat_num (0 = 1) (1 = 2) (30001 = 3) (60001 = 4) (90001 = 5) (110001 = 6) (150001 = 7) (200001 = 8)

* Replace category "-99" in pes_income2 with missing
gen income_cat_brut = pes_income2
replace income_cat_brut = . if pes_income2==-99

* Merge the two categorical variables
gen income_cat_merged = .
replace income_cat_merged = income_cat_brut if !missing(income_cat_brut)
replace income_cat_merged = cps_income_cat_num if missing(income_cat_brut) & !missing(cps_income_cat_num)

* Create the 0-1 scaled "income" variable
gen income = (income_cat_merged - 1) / 7

*Income (nominal, missing as a category)
gen income_missing = income_cat_merged
replace income_missing = 9 if pes_income2 == -99

* First Language(s)
gen langue_nominal = 1 if cps_lang_1 == 1 // Anglo
replace langue_nominal = 2 if cps_lang_2 == 1 // Franco
replace langue_nominal = 3 if cps_lang_1 == 1 & cps_lang_2 == 1 // Bilingual (French & English)
replace langue_nominal = 4 if cps_lang_3 == 1 // Other (allo)

* Language Binary (FR = 1)
gen franco = .
replace franco = 1 if langue_nominal == 2
replace franco = 0 if langue_nominal == 1 | langue_nominal == 4

* Generate minovis
gen minovis = .

replace minovis = 0 if pes_race_1 == 1


* Set minovis to 1 if any of the specified variables are 1
foreach var of varlist pes_race_2 pes_race_3 pes_race_4 pes_race_5 pes_race_6 pes_race_7 pes_race_8 pes_race_9 pes_race_10 pes_race_11 pes_race_12 pes_race_13 {
    replace minovis = 1 if `var' == 1
}

* Update minovis to missing (.) if pes_race_1 equals -99
replace minovis = . if pes_race_1 == -99


* Generate 'British Columbia'
gen region = 1


* Generate political interest
gen political_interest = cps_interest_1
replace political_interest = . if political_interest < 0 | political_interest > 10
replace political_interest = (political_interest - 0) / (10 - 0)

* Generate election_interest
gen election_interest = cps_intelection_1
replace election_interest = . if election_interest < 0 | election_interest > 10
replace election_interest = (election_interest - 0) / (10 - 0)


* Generate the 'civic_duty' variable
gen civic_duty = .

* Recode cps_duty values
replace civic_duty = 1 if cps_duty == 1
replace civic_duty = 0 if cps_duty == 2


* Generate the 'rural_urban' variable
gen rural_urban = pes_rural
replace rural_urban = . if rural_urban == 6

*Generate asset variables
gen asset1 = pes_own_1 == 1
gen asset2 = pes_own_2 == 1
gen asset3 = pes_own_3 == 1
gen asset4 = pes_own_4 == 1

*Generate index "asset"
gen asset = asset1 + asset2 + asset3 + asset4
replace asset = . if asset == 0
replace asset = 0 if pes_own_5 == 1
replace asset = asset / 4

*Gen economic well-being 
gen eco_well_being = (income + asset)/2

*Economic well-being (nominal, missing as a category)
gen eco_well_being_missing = eco_well_being
replace eco_well_being_missing = 2 if pes_own_1==-99 | pes_income2==-99

* Generate the string variable 'elecid'
gen elecid = "BC_2020"

* Gen weights
gen pes_weights = pes_weight_general

**********************************
***** INFORMAL PARTCIPATION ******	
**********************************
	
* Generate meeting (0-1)
gen meeting = .
replace meeting = 0 if pes_participation1_1 == 1
replace meeting = 0.33 if pes_participation1_1 == 2
replace meeting = 0.67 if pes_participation1_1 == 3	
replace meeting = 1 if pes_participation1_1 == 4

gen meeting_dicho = .
replace meeting_dicho = 0 if pes_participation1_1 == 1
replace meeting_dicho = 1 if inlist(pes_participation1_1, 2, 3, 4)

* Generate protest (0-1)
gen protest = .
replace protest = 0 if pes_participation1_2 == 1
replace protest = 0.33 if pes_participation1_2 == 2
replace protest = 0.67 if pes_participation1_2 == 3	
replace protest = 1 if pes_participation1_2 == 4

gen protest_dicho = .
replace protest_dicho = 0 if pes_participation1_2 == 1
replace protest_dicho = 1 if inlist(pes_participation1_2, 2, 3, 4)

* Generate boycott (0-1)
gen boycott = .
replace boycott = 0 if pes_participation1_3 == 1
replace boycott = 0.33 if pes_participation1_3 == 2
replace boycott = 0.67 if pes_participation1_3 == 3	
replace boycott = 1 if pes_participation1_3 == 4

gen boycott_dicho = .
replace boycott_dicho = 0 if pes_participation1_3 == 1
replace boycott_dicho = 1 if inlist(pes_participation1_3, 2, 3, 4)

* Generate petition (0-1)
gen petition = .
replace petition = 0 if pes_participation3_5 == 1
replace petition = 0.33 if pes_participation3_5 == 2
replace petition = 0.67 if pes_participation3_5 == 3	
replace petition = 1 if pes_participation3_5 == 4

gen petition_dicho = .
replace petition_dicho = 0 if pes_participation3_5 == 1
replace petition_dicho = 1 if inlist(pes_participation3_5, 2, 3, 4)

*****pes_participation2_1****


* Generate socialm (0-1)
gen socialm = .
replace socialm = 0 if pes_participation2_1 == 1
replace socialm = 0.33 if pes_participation2_1 == 2
replace socialm = 0.67 if pes_participation2_1 == 3	
replace socialm = 1 if pes_participation2_1 == 4

gen socialm_dicho = .
replace socialm_dicho = 0 if pes_participation2_1 == 1
replace socialm_dicho = 1 if inlist(pes_participation2_1, 2, 3, 4)

* Generate volunteer (0-1)
gen volunteer = .
replace volunteer = 0 if pes_participation2_2 == 1
replace volunteer = 0.33 if pes_participation2_2 == 2
replace volunteer = 0.67 if pes_participation2_2 == 3	
replace volunteer = 1 if pes_participation2_2 == 4

gen volunteer_dicho = .
replace volunteer_dicho = 0 if pes_participation2_2 == 1
replace volunteer_dicho = 1 if inlist(pes_participation2_2, 2, 3, 4)

* Generate contactRep (0-1)
gen contactRep = .
replace contactRep = 0 if pes_participation2_3 == 1
replace contactRep = 0.33 if pes_participation2_3 == 2
replace contactRep = 0.67 if pes_participation2_3 == 3	
replace contactRep = 1 if pes_participation2_3 == 4

gen contactRep_dicho = .
replace contactRep_dicho = 0 if pes_participation2_3 == 1
replace contactRep_dicho = 1 if inlist(pes_participation2_3, 2, 3, 4)

* Generate donate (0-1)
gen donate = .
replace donate = 0 if pes_participation2_4 == 1
replace donate = 0.33 if pes_participation2_4 == 2
replace donate = 0.67 if pes_participation2_4 == 3	
replace donate = 1 if pes_participation2_4 == 4
		
gen donate_dicho = .
replace donate_dicho = 0 if pes_participation2_4 == 1
replace donate_dicho = 1 if inlist(pes_participation2_4, 2, 3, 4)
	
*****pes_partic3****

* Generate circulatedInfo (0-1)
gen circulatedInfo = .
replace circulatedInfo = 0 if pes_participation3_3 == 1
replace circulatedInfo = 0.33 if pes_participation3_3 == 2
replace circulatedInfo = 0.67 if pes_participation3_3 == 3	
replace circulatedInfo = 1 if pes_participation3_3 == 4

gen circulatedInfo_dicho = .
replace circulatedInfo_dicho = 0 if pes_participation3_3 == 1
replace circulatedInfo_dicho = 1 if inlist(pes_participation3_3, 2, 3, 4)

* Generate usedSocialm (0-1)
gen usedSocialm = .
replace usedSocialm = 0 if pes_participation3_4 == 1
replace usedSocialm = 0.33 if pes_participation3_4 == 2
replace usedSocialm = 0.67 if pes_participation3_4 == 3	
replace usedSocialm = 1 if pes_participation3_4 == 4

gen usedSocialm_dicho = .
replace usedSocialm_dicho = 0 if pes_participation3_4 == 1
replace usedSocialm_dicho = 1 if inlist(pes_participation3_4, 2, 3, 4)
	

*****pes_partymember****

* Generate member (1 = yes)
gen member = .
replace member = 1 if pes_partymember == 1
replace member = 0 if inlist(pes_partymember, 2, 3)


******************
****  KEEP  ******
******************

keep turnout age gender gender_dicho sexuality sexuality_three education income income_cat_merged langue_nominal ///
	franco minovis region political_interest election_interest civic_duty rural_urban elecid meeting meeting_dicho ///
	protest protest_dicho boycott boycott_dicho petition petition_dicho socialm socialm_dicho volunteer volunteer_dicho ///
	contactRep contactRep_dicho donate donate_dicho circulatedInfo circulatedInfo_dicho usedSocialm usedSocialm_dicho ///
	member pes_weights asset eco_well_being income_missing


***************************
********Save
***************************

save "bc_prov.dta", replace









***
**************************************************************
**   DATASET : NEW BRUNSWICK 2020 ELECTION						**
**************************************************************
***
clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"

use "NB_2020_Election_Public_Release.dta", clear
	

set more off
numlabel, add



**************************************************************
** 					Generate variables 						**
**************************************************************

*Electoral Participation (0=abstained; 1=voted)
gen turnout=0 if inlist(pes_turnout, 2, 3, 4, 5, 6)
replace turnout=1 if pes_turnout==1

**********
**Bloc 1**
**********

*Age linear
gen age=cps_age_in_years
drop if age < 18

*Gender (0=woman; 1=man; 2=other)
gen gender=0 if cps_gender==2
replace gender=1 if cps_gender==1
replace gender=2 if cps_gender==3

gen gender_dicho=0 if cps_gender==2 // woman
replace gender_dicho=1 if cps_gender==1 // man


*Sexuality (0=heterosexual; 1=gay or lesbian; 2=bisexual; 3=other)
gen sexuality=0 if pes_orientation==1
replace sexuality=1 if pes_orientation==2
replace sexuality=2 if pes_orientation==3
replace sexuality=3 if pes_orientation==4

gen sexuality_three=sexuality
recode sexuality_three (3=.)

*Education (0=No university; 1=University Degree)
gen education=0 if cps_edu < 9 // No schooling to some university
replace education = 1 if inrange(cps_edu, 9, 11) // Bachelor's degree to Professional degree or doctorate


* Generate the categorical variable from the continuous variable
egen income_cat_num = cut(pes_income), at(0 1 30001 60001 90001 110001 150001 200001 10000000)
recode income_cat_num (0 = 1) (1 = 2) (30001 = 3) (60001 = 4) (90001 = 5) (110001 = 6) (150001 = 7) (200001 = 8)

* Replace category "-99" in pes_income2 with missing
gen income_cat_brut = pes_income2
replace income_cat_brut = . if pes_income2==-99

* Merge the two categorical variables
gen income_cat_merged = .
replace income_cat_merged = income_cat_brut if !missing(income_cat_brut)
replace income_cat_merged = income_cat_num if missing(income_cat_brut) & !missing(income_cat_num)

* Create the 0-1 scaled "income" variable
gen income = (income_cat_merged - 1) / 7

*Income (nominal, missing as a category)
gen income_missing = income_cat_merged
replace income_missing = 9 if pes_income2 == -99

* First Language(s)
gen langue_nominal = 1 if cps_lang_1 == 1 // Anglo
replace langue_nominal = 2 if cps_lang_2 == 1 // Franco
replace langue_nominal = 3 if cps_lang_1 == 1 & cps_lang_2 == 1 // Bilingual (French & English)
replace langue_nominal = 4 if cps_lang_3 == 1 // Other (allo)

* Language Binary (FR = 1)
gen franco = .
replace franco = 1 if langue_nominal == 2
replace franco = 0 if langue_nominal == 1 | langue_nominal == 3 | langue_nominal == 4

* Generate minovis
gen minovis = .

replace minovis = 0 if pes_race_1 == 1

* Set minovis to 1 if any of the specified variables are 1
foreach var of varlist pes_race_2 pes_race_3 pes_race_4 pes_race_5 pes_race_6 pes_race_7 pes_race_8 pes_race_9 pes_race_10 pes_race_11 pes_race_12 pes_race_13 {
    replace minovis = 1 if `var' == 1
}

* Update minovis to missing (.) if pes_race_1 equals -99
replace minovis = . if pes_race_1 == -99


* Generate 'Atlantic'
gen region = 5


* Generate political interest
gen political_interest = cps_interest_1
replace political_interest = . if political_interest < 0 | political_interest > 10
replace political_interest = (political_interest - 0) / (10 - 0)

* Generate election_interest
gen election_interest = cps_intelection_1
replace election_interest = . if election_interest < 0 | election_interest > 10
replace election_interest = (election_interest - 0) / (10 - 0)


* Generate the 'civic_duty' variable
gen civic_duty = .

* Recode cps_duty values
replace civic_duty = 1 if cps_duty == 1
replace civic_duty = 0 if cps_duty == 2


* Generate the 'rural_urban' variable
gen rural_urban = pes_rural
replace rural_urban = . if rural_urban == 6
replace rural_urban = . if rural_urban == -99

*Generate asset variables
gen asset1 = pes_own_1 == 1
gen asset2 = pes_own_2 == 1
gen asset3 = pes_own_3 == 1
gen asset4 = pes_own_4 == 1

*Generate index "asset"
gen asset = asset1 + asset2 + asset3 + asset4
replace asset = . if asset == 0
replace asset = 0 if pes_own_5 == 1
replace asset = asset / 4

*Gen economic well-being 
gen eco_well_being = (income + asset)/2

*Economic well-being (nominal, missing as a category)
gen eco_well_being_missing = eco_well_being
replace eco_well_being_missing = 2 if pes_own_1==-99 | pes_income2==-99

* Generate the string variable 'elecid'
gen elecid = "NB_2020"


* Gen weights
gen pes_weights = pes_weight_general

**********************************
***** INFORMAL PARTCIIPATION *****	
**********************************
	
* Generate meeting (0-1)
gen meeting = .
replace meeting = 0 if pes_participation1_1 == 1
replace meeting = 0.33 if pes_participation1_1 == 2
replace meeting = 0.67 if pes_participation1_1 == 3	
replace meeting = 1 if pes_participation1_1 == 4

gen meeting_dicho = .
replace meeting_dicho = 0 if pes_participation1_1 == 1
replace meeting_dicho = 1 if inlist(pes_participation1_1, 2, 3, 4)

* Generate protest (0-1)
gen protest = .
replace protest = 0 if pes_participation1_2 == 1
replace protest = 0.33 if pes_participation1_2 == 2
replace protest = 0.67 if pes_participation1_2 == 3	
replace protest = 1 if pes_participation1_2 == 4

gen protest_dicho = .
replace protest_dicho = 0 if pes_participation1_2 == 1
replace protest_dicho = 1 if inlist(pes_participation1_2, 2, 3, 4)

* Generate boycott (0-1)
gen boycott = .
replace boycott = 0 if pes_participation1_3 == 1
replace boycott = 0.33 if pes_participation1_3 == 2
replace boycott = 0.67 if pes_participation1_3 == 3	
replace boycott = 1 if pes_participation1_3 == 4

gen boycott_dicho = .
replace boycott_dicho = 0 if pes_participation1_3 == 1
replace boycott_dicho = 1 if inlist(pes_participation1_3, 2, 3, 4)

* Generate petition (0-1)
gen petition = .
replace petition = 0 if pes_participation3_5 == 1
replace petition = 0.33 if pes_participation3_5 == 2
replace petition = 0.67 if pes_participation3_5 == 3	
replace petition = 1 if pes_participation3_5 == 4

gen petition_dicho = .
replace petition_dicho = 0 if pes_participation3_5 == 1
replace petition_dicho = 1 if inlist(pes_participation3_5, 2, 3, 4)

*****pes_participation2*****

* Generate socialm (0-1)
gen socialm = .
replace socialm = 0 if pes_participation2_1 == 1
replace socialm = 0.33 if pes_participation2_1 == 2
replace socialm = 0.67 if pes_participation2_1 == 3	
replace socialm = 1 if pes_participation2_1 == 4

gen socialm_dicho = .
replace socialm_dicho = 0 if pes_participation2_1 == 1
replace socialm_dicho = 1 if inlist(pes_participation2_1, 2, 3, 4)

* Generate volunteer (0-1)
gen volunteer = .
replace volunteer = 0 if pes_participation2_2 == 1
replace volunteer = 0.33 if pes_participation2_2 == 2
replace volunteer = 0.67 if pes_participation2_2 == 3	
replace volunteer = 1 if pes_participation2_2 == 4

gen volunteer_dicho = .
replace volunteer_dicho = 0 if pes_participation2_2 == 1
replace volunteer_dicho = 1 if inlist(pes_participation2_2, 2, 3, 4)

* Generate contactRep (0-1)
gen contactRep = .
replace contactRep = 0 if pes_participation2_3 == 1
replace contactRep = 0.33 if pes_participation2_3 == 2
replace contactRep = 0.67 if pes_participation2_3 == 3	
replace contactRep = 1 if pes_participation2_3 == 4

gen contactRep_dicho = .
replace contactRep_dicho = 0 if pes_participation2_3 == 1
replace contactRep_dicho = 1 if inlist(pes_participation2_3, 2, 3, 4)

* Generate donate (0-1)
gen donate = .
replace donate = 0 if pes_participation2_4 == 1
replace donate = 0.33 if pes_participation2_4 == 2
replace donate = 0.67 if pes_participation2_4 == 3	
replace donate = 1 if pes_participation2_4 == 4

gen donate_dicho = .
replace donate_dicho = 0 if pes_participation2_4 == 1
replace donate_dicho = 1 if inlist(pes_participation2_4, 2, 3, 4)

	
*****pes_participation3*****

* Generate circulatedInfo (0-1)
gen circulatedInfo = .
replace circulatedInfo = 0 if pes_participation3_3 == 1
replace circulatedInfo = 0.33 if pes_participation3_3 == 2
replace circulatedInfo = 0.67 if pes_participation3_3 == 3	
replace circulatedInfo = 1 if pes_participation3_3 == 4

gen circulatedInfo_dicho = .
replace circulatedInfo_dicho = 0 if pes_participation3_3 == 1
replace circulatedInfo_dicho = 1 if inlist(pes_participation3_3, 2, 3, 4)

* Generate usedSocialm (0-1)
gen usedSocialm = .
replace usedSocialm = 0 if pes_participation3_4 == 1
replace usedSocialm = 0.33 if pes_participation3_4 == 2
replace usedSocialm = 0.67 if pes_participation3_4 == 3	
replace usedSocialm = 1 if pes_participation3_4 == 4

gen usedSocialm_dicho = .
replace usedSocialm_dicho = 0 if pes_participation3_4 == 1
replace usedSocialm_dicho = 1 if inlist(pes_participation3_4, 2, 3, 4)	

*****pes_partymember****

* Generate member (1 = yes)
gen member = .
replace member = 1 if pes_partymember == 1
replace member = 0 if inlist(pes_partymember, 2, 3)



******************
****  KEEP  ******
******************

keep turnout age gender gender_dicho sexuality sexuality_three education income income_cat_merged langue_nominal ///
	franco minovis region political_interest election_interest civic_duty rural_urban elecid meeting meeting_dicho ///
	protest protest_dicho boycott boycott_dicho petition petition_dicho socialm socialm_dicho volunteer volunteer_dicho ///
	contactRep contactRep_dicho donate donate_dicho circulatedInfo circulatedInfo_dicho usedSocialm usedSocialm_dicho ///
	member pes_weights asset eco_well_being income_missing


***************************
********Save***************
***************************

save "nb_prov.dta", replace


***
**************************************************************
**   DATASET :  NL 2021 ELECTION				     		**
**************************************************************
***

clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"

use "NL 2021_Public_Release_Final.dta", clear
	

set more off
numlabel, add


**************************************************************
** 					Generate variables 						**
**************************************************************

*Electoral Participation (0=abstained; 1=voted)
gen turnout=0 if inlist(pes_turnout, 2, 3, 4, 5, 6)
replace turnout=1 if pes_turnout==1

**********
**Bloc 1**
**********

*Age linear
gen age=cps_age_in_years
drop if age < 18

*Gender (0=woman; 1=man; 2=other)
gen gender=0 if cps_genderid==5
replace gender=1 if cps_genderid==1
replace gender=2 if cps_genderid==3
replace gender=2 if cps_genderid==4


gen gender_dicho=0 if cps_genderid==5 // woman
replace gender_dicho=1 if cps_genderid==1 // man


*Sexuality (0=heterosexual; 1=gay or lesbian; 2=bisexual; 3=other)
gen sexuality=0 if pes_orientation==1
replace sexuality=1 if pes_orientation==2
replace sexuality=2 if pes_orientation==3
replace sexuality=3 if pes_orientation==4

gen sexuality_three=sexuality
recode sexuality_three (3=.)

*Education (0=No university; 1=University Degree)
gen education=0 if cps_edu < 9 // No schooling to some university
replace education = 1 if inrange(cps_edu, 9, 11) // Bachelor's degree to Professional degree or doctorate


* Generate the categorical variable from the continuous variable
egen income_cat_num = cut(pes_income), at(0 1 30001 60001 90001 110001 150001 200001 10000000)
recode income_cat_num (0 = 1) (1 = 2) (30001 = 3) (60001 = 4) (90001 = 5) (110001 = 6) (150001 = 7) (200001 = 8)

* Replace category "-99" in pes_income2 with missing
gen income_cat_brut = pes_income1
replace income_cat_brut = . if pes_income1==-99

* Merge the two categorical variables
gen income_cat_merged = .
replace income_cat_merged = income_cat_brut if !missing(income_cat_brut)
replace income_cat_merged = income_cat_num if missing(income_cat_brut) & !missing(income_cat_num)

* Create the 0-1 scaled "income" variable
gen income = (income_cat_merged - 1) / 7

*Income (nominal, missing as a category)
gen income_missing = income_cat_merged
replace income_missing = 9 if pes_income1 == -99


* First Language(s)
gen langue_nominal = 1 if cps_lang_1 == 1 // Anglo
replace langue_nominal = 2 if cps_lang_2 == 1 // Franco
replace langue_nominal = 3 if cps_lang_1 == 1 & cps_lang_2 == 1 // Bilingual (French & English)
replace langue_nominal = 4 if cps_lang_3 == 1 // Other (allo)


* Language Binary (FR = 1)
gen franco = .
replace franco = 1 if langue_nominal == 2
replace franco = 0 if langue_nominal == 1 | langue_nominal == 3 | langue_nominal == 4


* Generate minovis
gen minovis = .

replace minovis = 0 if cps_race_1 == 1

* Set minovis to 1 if any of the specified variables are 1
foreach var of varlist cps_race_2 cps_race_3 cps_race_4 cps_race_5 cps_race_6 cps_race_7 cps_race_8 cps_race_9 cps_race_10 cps_race_11 cps_race_12 cps_race_13 {
    replace minovis = 1 if `var' == 1
}


* Generate 'Atlantic'
gen region = 5


* Generate political interest
gen political_interest = cps_interest_1
replace political_interest = . if political_interest < 0 | political_interest > 10
replace political_interest = (political_interest - 0) / (10 - 0)

* Generate election_interest
gen election_interest = cps_intelection_1
replace election_interest = . if election_interest < 0 | election_interest > 10
replace election_interest = (election_interest - 0) / (10 - 0)


* Generate the 'civic_duty' variable
gen civic_duty = .

* Recode cps_duty values
replace civic_duty = 1 if cps_duty == 1
replace civic_duty = 0 if cps_duty == 2


* Generate the 'rural_urban' variable
gen rural_urban = pes_rural

*Generate asset variables
gen asset1 = pes_own_1 == 1
gen asset2 = pes_own_2 == 1
gen asset3 = pes_own_3 == 1
gen asset4 = pes_own_4 == 1

*Generate index "asset"
gen asset = asset1 + asset2 + asset3 + asset4
replace asset = . if asset == 0
replace asset = 0 if pes_own_5 == 1
replace asset = asset / 4

*Gen economic well-being 
gen eco_well_being = (income + asset)/2

*Economic well-being (nominal, missing as a category)
gen eco_well_being_missing = eco_well_being
replace eco_well_being_missing = 2 if (pes_own_1==-99 & pes_own_2==-99 & pes_own_3==-99 & pes_own_4==-99 & pes_own_5==-99) | pes_income1==-99

* Generate the string variable 'elecid'
gen elecid = "NL_2021"

* Gen weights
gen pes_weights = pes_weight_general

**********************************
***** INFORMAL PARTCIIPATION *****	
**********************************
	
* Generate meeting (0-1)
gen meeting = .
replace meeting = 0 if pes_participation1_1 == 1
replace meeting = 0.33 if pes_participation1_1 == 2
replace meeting = 0.67 if pes_participation1_1 == 3	
replace meeting = 1 if pes_participation1_1 == 4

gen meeting_dicho = .
replace meeting_dicho = 0 if pes_participation1_1 == 1
replace meeting_dicho = 1 if inlist(pes_participation1_1, 2, 3, 4)

* Generate protest (0-1)
gen protest = .
replace protest = 0 if pes_participation1_2 == 1
replace protest = 0.33 if pes_participation1_2 == 2
replace protest = 0.67 if pes_participation1_2 == 3	
replace protest = 1 if pes_participation1_2 == 4

gen protest_dicho = .
replace protest_dicho = 0 if pes_participation1_2 == 1
replace protest_dicho = 1 if inlist(pes_participation1_2, 2, 3, 4)

* Generate boycott (0-1)
gen boycott = .
replace boycott = 0 if pes_participation1_3 == 1
replace boycott = 0.33 if pes_participation1_3 == 2
replace boycott = 0.67 if pes_participation1_3 == 3	
replace boycott = 1 if pes_participation1_3 == 4

gen boycott_dicho = .
replace boycott_dicho = 0 if pes_participation1_3 == 1
replace boycott_dicho = 1 if inlist(pes_participation1_3, 2, 3, 4)

* Generate petition (0-1)
gen petition = .
replace petition = 0 if pes_participation3_5 == 1
replace petition = 0.33 if pes_participation3_5 == 2
replace petition = 0.67 if pes_participation3_5 == 3	
replace petition = 1 if pes_participation3_5 == 4

gen petition_dicho = .
replace petition_dicho = 0 if pes_participation3_5 == 1
replace petition_dicho = 1 if inlist(pes_participation3_5, 2, 3, 4)


*****pes_partic2*****


* Generate socialm (0-1)
gen socialm = .
replace socialm = 0 if pes_participation2_1 == 1
replace socialm = 0.33 if pes_participation2_1 == 2
replace socialm = 0.67 if pes_participation2_1 == 3	
replace socialm = 1 if pes_participation2_1 == 4

gen socialm_dicho = .
replace socialm_dicho = 0 if pes_participation2_1 == 1
replace socialm_dicho = 1 if inlist(pes_participation2_1, 2, 3, 4)

* Generate volunteer (0-1)
gen volunteer = .
replace volunteer = 0 if pes_participation2_2 == 1
replace volunteer = 0.33 if pes_participation2_2 == 2
replace volunteer = 0.67 if pes_participation2_2 == 3	
replace volunteer = 1 if pes_participation2_2 == 4

gen volunteer_dicho = .
replace volunteer_dicho = 0 if pes_participation2_2 == 1
replace volunteer_dicho = 1 if inlist(pes_participation2_2, 2, 3, 4)

* Generate contactRep (0-1)
gen contactRep = .
replace contactRep = 0 if pes_participation2_3 == 1
replace contactRep = 0.33 if pes_participation2_3 == 2
replace contactRep = 0.67 if pes_participation2_3 == 3	
replace contactRep = 1 if pes_participation2_3 == 4

gen contactRep_dicho = .
replace contactRep_dicho = 0 if pes_participation2_3 == 1
replace contactRep_dicho = 1 if inlist(pes_participation2_3, 2, 3, 4)

* Generate donate (0-1)
gen donate = .
replace donate = 0 if pes_participation2_4 == 1
replace donate = 0.33 if pes_participation2_4 == 2
replace donate = 0.67 if pes_participation2_4 == 3	
replace donate = 1 if pes_participation2_4 == 4

gen donate_dicho = .
replace donate_dicho = 0 if pes_participation2_4 == 1
replace donate_dicho = 1 if inlist(pes_participation2_4, 2, 3, 4)		

	
*****pes_partic3****

* Generate circulatedInfo (0-1)
gen circulatedInfo = .
replace circulatedInfo = 0 if pes_participation3_3 == 1
replace circulatedInfo = 0.33 if pes_participation3_3 == 2
replace circulatedInfo = 0.67 if pes_participation3_3 == 3	
replace circulatedInfo = 1 if pes_participation3_3 == 4

gen circulatedInfo_dicho = .
replace circulatedInfo_dicho = 0 if pes_participation3_3 == 1
replace circulatedInfo_dicho = 1 if inlist(pes_participation3_3, 2, 3, 4)

* Generate usedSocialm (0-1)
gen usedSocialm = .
replace usedSocialm = 0 if pes_participation3_4 == 1
replace usedSocialm = 0.33 if pes_participation3_4 == 2
replace usedSocialm = 0.67 if pes_participation3_4 == 3	
replace usedSocialm = 1 if pes_participation3_4 == 4

gen usedSocialm_dicho = .
replace usedSocialm_dicho = 0 if pes_participation3_4 == 1
replace usedSocialm_dicho = 1 if inlist(pes_participation3_4, 2, 3, 4)
	

*****pes_partymember****

* Generate member (1 = yes)
gen member = .
replace member = 1 if pes_partymember == 1
replace member = 0 if inlist(pes_partymember, 2, 3)




******************
****  KEEP  ******
******************

keep turnout age gender gender_dicho sexuality sexuality_three education income income_cat_merged langue_nominal ///
	franco minovis region political_interest election_interest civic_duty rural_urban elecid meeting meeting_dicho ///
	protest protest_dicho boycott boycott_dicho petition petition_dicho socialm socialm_dicho volunteer volunteer_dicho ///
	contactRep contactRep_dicho donate donate_dicho circulatedInfo circulatedInfo_dicho usedSocialm usedSocialm_dicho ///
	member pes_weights asset eco_well_being income_missing

***************************
********Save***************
***************************

save "nl_prov.dta", replace


***
**************************************************************
**   DATASET : Nova Scotia 2021 ELECTION					**
**************************************************************
***

clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"

use "2021 Nova Scotia Election Study v1.dta", clear
	

set more off
numlabel, add


**************************************************************
** 					Generate variables 						**
**************************************************************

gen turnout=0 if inlist(pes_turnout, 2, 3, 4, 5, 6)
replace turnout=1 if pes_turnout==1

**********
**Bloc 1**
**********

*Age linear
gen age=cps_age_in_years
drop if age < 18

*Gender (0=woman; 1=man; 2=other)
gen gender=0 if cps_genderid==2
replace gender=1 if cps_genderid==1
replace gender=2 if cps_genderid==3
replace gender=2 if cps_genderid==4


gen gender_dicho=0 if cps_genderid==2 // woman
replace gender_dicho=1 if cps_genderid==1 // man


*Sexuality (0=heterosexual; 1=gay or lesbian; 2=bisexual; 3=other)
gen sexuality=0 if pes_orientation==1
replace sexuality=1 if pes_orientation==2
replace sexuality=2 if pes_orientation==3
replace sexuality=3 if pes_orientation==4

gen sexuality_three=sexuality
recode sexuality_three (3=.)

*Education (0=No university; 1=University Degree)
gen education=0 if cps_edu < 9 // No schooling to some university
replace education = 1 if inrange(cps_edu, 9, 11) // Bachelor's degree to Professional degree or doctorate


* Generate the categorical variable from the continuous variable
egen income_cat_num = cut(cps_income), at(0 1 30001 60001 90001 110001 150001 200001 10000000)
recode income_cat_num (0 = 1) (1 = 2) (30001 = 3) (60001 = 4) (90001 = 5) (110001 = 6) (150001 = 7) (200001 = 8)

* Replace category "-99" in pes_income2 with missing
gen income_cat_brut = cps_income2
replace income_cat_brut = . if cps_income2==-99

* Merge the two categorical variables
gen income_cat_merged = .
replace income_cat_merged = income_cat_brut if !missing(income_cat_brut)
replace income_cat_merged = income_cat_num if missing(income_cat_brut) & !missing(income_cat_num)

* Create the 0-1 scaled "income" variable
gen income = (income_cat_merged - 1) / 7

*Income (nominal, missing as a category)
gen income_missing = income_cat_merged
replace income_missing = 9 if cps_income2 == -99


*First Language(s) 
gen langue_nominal = 1 if cps_lang_1 == 1 // Anglo
replace langue_nominal = 2 if cps_lang_2 == 1 // Franco
replace langue_nominal = 3 if cps_lang_1 == 1 & cps_lang_2 == 1 // Bilingual (French & English)
replace langue_nominal = 4 if cps_lang_3 == 1 // Other (allo)

* Language Binary (FR = 1)
gen franco = .
replace franco = 1 if langue_nominal == 2
replace franco = 0 if langue_nominal == 1 | langue_nominal == 3 | langue_nominal == 4

* Generate minovis
gen minovis = .

replace minovis = 0 if pes_race_1 == 1

* Set minovis to 1 if any of the specified variables are 1
foreach var of varlist pes_race_2 pes_race_3 pes_race_4 pes_race_5 pes_race_6 pes_race_7 pes_race_8 pes_race_9 pes_race_10 pes_race_11 pes_race_12 pes_race_13 {
    replace minovis = 1 if `var' == 1
}

* Generate 'Atlantic'
gen region = 5

* Generate political interest
gen political_interest = cps_interest_1
replace political_interest = . if political_interest < 0 | political_interest > 10
replace political_interest = (political_interest - 0) / (10 - 0)

* Generate election_interest
gen election_interest = cps_intelection_1
replace election_interest = . if election_interest < 0 | election_interest > 10
replace election_interest = (election_interest - 0) / (10 - 0)


* Generate the 'civic_duty' variable
gen civic_duty = .

* Recode cps_duty values
replace civic_duty = 1 if cps_duty == 1
replace civic_duty = 0 if cps_duty == 2


* Generate the 'rural_urban' variable
gen rural_urban = pes_rural
replace rural_urban = . if rural_urban == -99

*Generate asset variables
gen asset1 = pes_own_1 == 1
gen asset2 = pes_own_2 == 1
gen asset3 = pes_own_3 == 1
gen asset4 = pes_own_4 == 1

*Generate index "asset"
gen asset = asset1 + asset2 + asset3 + asset4
replace asset = . if asset == 0
replace asset = 0 if pes_own_5 == 1
replace asset = asset / 4

*Gen economic well-being 
gen eco_well_being = (income + asset)/2

*Economic well-being (nominal, missing as a category)
gen eco_well_being_missing = eco_well_being
replace eco_well_being_missing = 2 if (pes_own_1==-99 & pes_own_2==-99 & pes_own_3==-99 & pes_own_4==-99 & pes_own_5==-99) | cps_income2==-99


* Generate the string variable 'elecid'
gen elecid = "NS_2021"

* Gen weights
gen pes_weights = pes_weight_general

**********************************
***** INFORMAL PARTCIIPATION *****	
**********************************
	
* Generate meeting (0-1)
gen meeting = .
replace meeting = 0 if pes_participation1_1 == 1
replace meeting = 0.33 if pes_participation1_1 == 2
replace meeting = 0.67 if pes_participation1_1 == 3	
replace meeting = 1 if pes_participation1_1 == 4

gen meeting_dicho = .
replace meeting_dicho = 0 if pes_participation1_1 == 1
replace meeting_dicho = 1 if inlist(pes_participation1_1, 2, 3, 4)

* Generate protest (0-1)
gen protest = .
replace protest = 0 if pes_participation1_2 == 1
replace protest = 0.33 if pes_participation1_2 == 2
replace protest = 0.67 if pes_participation1_2 == 3	
replace protest = 1 if pes_participation1_2 == 4

gen protest_dicho = .
replace protest_dicho = 0 if pes_participation1_2 == 1
replace protest_dicho = 1 if inlist(pes_participation1_2, 2, 3, 4)

* Generate boycott (0-1)
gen boycott = .
replace boycott = 0 if pes_participation1_3 == 1
replace boycott = 0.33 if pes_participation1_3 == 2
replace boycott = 0.67 if pes_participation1_3 == 3	
replace boycott = 1 if pes_participation1_3 == 4

gen boycott_dicho = .
replace boycott_dicho = 0 if pes_participation1_3 == 1
replace boycott_dicho = 1 if inlist(pes_participation1_3, 2, 3, 4)

* Generate petition (0-1)
gen petition = .
replace petition = 0 if pes_participation3_5 == 1
replace petition = 0.33 if pes_participation3_5 == 2
replace petition = 0.67 if pes_participation3_5 == 3	
replace petition = 1 if pes_participation3_5 == 4

gen petition_dicho = .
replace petition_dicho = 0 if pes_participation3_5 == 1
replace petition_dicho = 1 if inlist(pes_participation3_5, 2, 3, 4)


*****pes_partic2****


* Generate socialm (0-1)
gen socialm = .
replace socialm = 0 if pes_participation2_1 == 1
replace socialm = 0.33 if pes_participation2_1 == 2
replace socialm = 0.67 if pes_participation2_1 == 3	
replace socialm = 1 if pes_participation2_1 == 4

gen socialm_dicho = .
replace socialm_dicho = 0 if pes_participation2_1 == 1
replace socialm_dicho = 1 if inlist(pes_participation2_1, 2, 3, 4)

* Generate volunteer (0-1)
gen volunteer = .
replace volunteer = 0 if pes_participation2_2 == 1
replace volunteer = 0.33 if pes_participation2_2 == 2
replace volunteer = 0.67 if pes_participation2_2 == 3	
replace volunteer = 1 if pes_participation2_2 == 4

gen volunteer_dicho = .
replace volunteer_dicho = 0 if pes_participation2_2 == 1
replace volunteer_dicho = 1 if inlist(pes_participation2_2, 2, 3, 4)

* Generate contactRep (0-1)
gen contactRep = .
replace contactRep = 0 if pes_participation2_3 == 1
replace contactRep = 0.33 if pes_participation2_3 == 2
replace contactRep = 0.67 if pes_participation2_3 == 3	
replace contactRep = 1 if pes_participation2_3 == 4

gen contactRep_dicho = .
replace contactRep_dicho = 0 if pes_participation2_3 == 1
replace contactRep_dicho = 1 if inlist(pes_participation2_3, 2, 3, 4)

* Generate donate (0-1)
gen donate = .
replace donate = 0 if pes_participation2_4 == 1
replace donate = 0.33 if pes_participation2_4 == 2
replace donate = 0.67 if pes_participation2_4 == 3	
replace donate = 1 if pes_participation2_4 == 4
		
gen donate_dicho = .
replace donate_dicho = 0 if pes_participation2_4 == 1
replace donate_dicho = 1 if inlist(pes_participation2_4, 2, 3, 4)
	
*****pes_partic3****

* Generate circulatedInfo (0-1)
gen circulatedInfo = .
replace circulatedInfo = 0 if pes_participation3_3 == 1
replace circulatedInfo = 0.33 if pes_participation3_3 == 2
replace circulatedInfo = 0.67 if pes_participation3_3 == 3	
replace circulatedInfo = 1 if pes_participation3_3 == 4

gen circulatedInfo_dicho = .
replace circulatedInfo_dicho = 0 if pes_participation3_3 == 1
replace circulatedInfo_dicho = 1 if inlist(pes_participation3_3, 2, 3, 4)

* Generate usedSocialm (0-1)
gen usedSocialm = .
replace usedSocialm = 0 if pes_participation3_4 == 1
replace usedSocialm = 0.33 if pes_participation3_4 == 2
replace usedSocialm = 0.67 if pes_participation3_4 == 3	
replace usedSocialm = 1 if pes_participation3_4 == 4

gen usedSocialm_dicho = .
replace usedSocialm_dicho = 0 if pes_participation3_4 == 1
replace usedSocialm_dicho = 1 if inlist(pes_participation3_4, 2, 3, 4)	

*****pes_partymember****

* Generate member (1 = yes)
gen member = .
replace member = 1 if pes_partymember == 1
replace member = 0 if inlist(pes_partymember, 2, 3)



******************
****  KEEP  ******
******************

keep turnout age gender gender_dicho sexuality sexuality_three education income income_cat_merged langue_nominal ///
	franco minovis region political_interest election_interest civic_duty rural_urban elecid meeting meeting_dicho ///
	protest protest_dicho boycott boycott_dicho petition petition_dicho socialm socialm_dicho volunteer volunteer_dicho ///
	contactRep contactRep_dicho donate donate_dicho circulatedInfo circulatedInfo_dicho usedSocialm usedSocialm_dicho ///
	member pes_weights asset eco_well_being income_missing

***************************
********Save***************
***************************

save "ns_prov.dta", replace


***
**************************************************************
**   DATASET : SASK 2020 ELECTION							**
**************************************************************
***

clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"

use "SK_2020_Public_Release_Final.dta", clear
	

set more off
numlabel, add


**************************************************************
** 					Generate variables 						**
**************************************************************

*Electoral Participation (0=abstained; 1=voted)
gen turnout=0 if inlist(pes_turnout, 2, 3, 4, 5, 6)
replace turnout=1 if pes_turnout==1

**********
**Bloc 1**
**********

*Age linear
gen age=cps_age_in_years
drop if age < 18

*Gender (0=woman; 1=man; 2=other)
gen gender=0 if cps_gender==2
replace gender=1 if cps_gender==1
replace gender=2 if cps_gender==3

gen gender_dicho=0 if cps_gender==2 // woman
replace gender_dicho=1 if cps_gender==1 // man


*Sexuality (0=heterosexual; 1=gay or lesbian; 2=bisexual; 3=other)
gen sexuality=0 if pes_orientation==1
replace sexuality=1 if pes_orientation==2
replace sexuality=2 if pes_orientation==3
replace sexuality=3 if pes_orientation==4

gen sexuality_three=sexuality
recode sexuality_three (3=.)

*Education (0=No university; 1=University Degree)
gen education=0 if cps_edu < 9 // No schooling to some university
replace education = 1 if inrange(cps_edu, 9, 11) // Bachelor's degree to Professional degree or doctorate


* Generate the categorical variable from the continuous variable
egen income_cat_num = cut(pes_income), at(0 1 30001 60001 90001 110001 150001 200001 10000000)
recode income_cat_num (0 = 1) (1 = 2) (30001 = 3) (60001 = 4) (90001 = 5) (110001 = 6) (150001 = 7) (200001 = 8)

* Replace category "-99" in pes_income2 with missing
gen income_cat_brut = pes_income2
replace income_cat_brut = . if pes_income2==-99

* Merge the two categorical variables
gen income_cat_merged = .
replace income_cat_merged = income_cat_brut if !missing(income_cat_brut)
replace income_cat_merged = income_cat_num if missing(income_cat_brut) & !missing(income_cat_num)
replace income_cat_merged = . if pes_income2==-99

* Create the 0-1 scaled "income" variable
gen income = (income_cat_merged - 1) / 7

*Income (nominal, missing as a category)
gen income_missing = income_cat_merged
replace income_missing = 9 if pes_income2 == -99


*First Language(s) 
gen langue_nominal = 1 if cps_lang_1 == 1 // Anglo
replace langue_nominal = 2 if cps_lang_2 == 1 // Franco
replace langue_nominal = 3 if cps_lang_1 == 1 & cps_lang_2 == 1 // Bilingual (French & English)
replace langue_nominal = 4 if cps_lang_3 == 1 // Other (allo)

* Language Binary (FR = 1)
gen franco = .
replace franco = 1 if langue_nominal == 2
replace franco = 0 if langue_nominal == 1 | langue_nominal == 3 | langue_nominal == 4


* Generate minovis
gen minovis = .

replace minovis = 0 if pes_race_1 == 1

* Set minovis to 1 if any of the specified variables are 1
foreach var of varlist pes_race_2 pes_race_3 pes_race_4 pes_race_5 pes_race_6 pes_race_7 pes_race_8 pes_race_9 pes_race_10 pes_race_11 pes_race_12 pes_race_13 {
    replace minovis = 1 if `var' == 1
}


* Generate 'Prairies'
gen region = 2


* Generate political interest
gen political_interest = cps_interest_1
replace political_interest = . if political_interest < 0 | political_interest > 10
replace political_interest = (political_interest - 0) / (10 - 0)

* Generate election_interest
gen election_interest = cps_intelection_1
replace election_interest = . if election_interest < 0 | election_interest > 10
replace election_interest = (election_interest - 0) / (10 - 0)


* Generate the 'civic_duty' variable
gen civic_duty = .

* Recode cps_duty values
replace civic_duty = 1 if cps_duty == 1
replace civic_duty = 0 if cps_duty == 2


* Generate the 'rural_urban' variable
gen rural_urban = pes_rural
replace rural_urban = . if rural_urban == 6

*Generate asset variables
gen asset1 = pes_own_1 == 1
gen asset2 = pes_own_2 == 1
gen asset3 = pes_own_3 == 1
gen asset4 = pes_own_4 == 1

*Generate index "asset"
gen asset = asset1 + asset2 + asset3 + asset4
replace asset = . if asset == 0
replace asset = 0 if pes_own_5 == 1
replace asset = asset / 4

*Gen economic well-being 
gen eco_well_being = (income + asset)/2

*Economic well-being (nominal, missing as a category)
gen eco_well_being_missing = eco_well_being
replace eco_well_being_missing = 2 if (pes_own_1==-99 & pes_own_2==-99 & pes_own_3==-99 & pes_own_4==-99 & pes_own_5==-99) | pes_income2==-99

* Generate the string variable 'elecid'
gen elecid = "SASK_2020"

* Gen weights
gen pes_weights = pes_weight_general

**********************************
***** INFORMAL PARTCIIPATION *****	
**********************************
	
* Generate meeting (0-1)
gen meeting = .
replace meeting = 0 if pes_participation1_1 == 1
replace meeting = 0.33 if pes_participation1_1 == 2
replace meeting = 0.67 if pes_participation1_1 == 3	
replace meeting = 1 if pes_participation1_1 == 4

gen meeting_dicho = .
replace meeting_dicho = 0 if pes_participation1_1 == 1
replace meeting_dicho = 1 if inlist(pes_participation1_1, 2, 3, 4)

* Generate protest (0-1)
gen protest = .
replace protest = 0 if pes_participation1_2 == 1
replace protest = 0.33 if pes_participation1_2 == 2
replace protest = 0.67 if pes_participation1_2 == 3	
replace protest = 1 if pes_participation1_2 == 4

gen protest_dicho = .
replace protest_dicho = 0 if pes_participation1_2 == 1
replace protest_dicho = 1 if inlist(pes_participation1_2, 2, 3, 4)

* Generate boycott (0-1)
gen boycott = .
replace boycott = 0 if pes_participation1_3 == 1
replace boycott = 0.33 if pes_participation1_3 == 2
replace boycott = 0.67 if pes_participation1_3 == 3	
replace boycott = 1 if pes_participation1_3 == 4

gen boycott_dicho = .
replace boycott_dicho = 0 if pes_participation1_3 == 1
replace boycott_dicho = 1 if inlist(pes_participation1_3, 2, 3, 4)

* Generate petition (0-1)
gen petition = .
replace petition = 0 if pes_participation3_5 == 1
replace petition = 0.33 if pes_participation3_5 == 2
replace petition = 0.67 if pes_participation3_5 == 3	
replace petition = 1 if pes_participation3_5 == 4

gen petition_dicho = .
replace petition_dicho = 0 if pes_participation3_5 == 1
replace petition_dicho = 1 if inlist(pes_participation3_5, 2, 3, 4)

*****pes_partic2****


* Generate socialm (0-1)
gen socialm = .
replace socialm = 0 if pes_participation2_1 == 1
replace socialm = 0.33 if pes_participation2_1 == 2
replace socialm = 0.67 if pes_participation2_1 == 3	
replace socialm = 1 if pes_participation2_1 == 4

gen socialm_dicho = .
replace socialm_dicho = 0 if pes_participation2_1 == 1
replace socialm_dicho = 1 if inlist(pes_participation2_1, 2, 3, 4)

* Generate volunteer (0-1)
gen volunteer = .
replace volunteer = 0 if pes_participation2_2 == 1
replace volunteer = 0.33 if pes_participation2_2 == 2
replace volunteer = 0.67 if pes_participation2_2 == 3	
replace volunteer = 1 if pes_participation2_2 == 4

gen volunteer_dicho = .
replace volunteer_dicho = 0 if pes_participation2_2 == 1
replace volunteer_dicho = 1 if inlist(pes_participation2_2, 2, 3, 4)

* Generate contactRep (0-1)
gen contactRep = .
replace contactRep = 0 if pes_participation2_3 == 1
replace contactRep = 0.33 if pes_participation2_3 == 2
replace contactRep = 0.67 if pes_participation2_3 == 3	
replace contactRep = 1 if pes_participation2_3 == 4

gen contactRep_dicho = .
replace contactRep_dicho = 0 if pes_participation2_3 == 1
replace contactRep_dicho = 1 if inlist(pes_participation2_3, 2, 3, 4)

* Generate donate (0-1)
gen donate = .
replace donate = 0 if pes_participation2_4 == 1
replace donate = 0.33 if pes_participation2_4 == 2
replace donate = 0.67 if pes_participation2_4 == 3	
replace donate = 1 if pes_participation2_4 == 4
		
gen donate_dicho = .
replace donate_dicho = 0 if pes_participation2_4 == 1
replace donate_dicho = 1 if inlist(pes_participation2_4, 2, 3, 4)
	
*****pes_partic3****

* Generate circulatedInfo (0-1)
gen circulatedInfo = .
replace circulatedInfo = 0 if pes_participation3_3 == 1
replace circulatedInfo = 0.33 if pes_participation3_3 == 2
replace circulatedInfo = 0.67 if pes_participation3_3 == 3	
replace circulatedInfo = 1 if pes_participation3_3 == 4

gen circulatedInfo_dicho = .
replace circulatedInfo_dicho = 0 if pes_participation3_3 == 1
replace circulatedInfo_dicho = 1 if inlist(pes_participation3_3, 2, 3, 4)

* Generate usedSocialm (0-1)
gen usedSocialm = .
replace usedSocialm = 0 if pes_participation3_4 == 1
replace usedSocialm = 0.33 if pes_participation3_4 == 2
replace usedSocialm = 0.67 if pes_participation3_4 == 3	
replace usedSocialm = 1 if pes_participation3_4 == 4
	
gen usedSocialm_dicho = .
replace usedSocialm_dicho = 0 if pes_participation3_4 == 1
replace usedSocialm_dicho = 1 if inlist(pes_participation3_4, 2, 3, 4)

*****pes_partymember****

* Generate member (1 = yes)
gen member = .
replace member = 1 if pes_partymember == 1
replace member = 0 if inlist(pes_partymember, 2, 3)


******************
****  KEEP  ******
******************

keep turnout age gender gender_dicho sexuality sexuality_three education income income_cat_merged langue_nominal ///
	franco minovis region political_interest election_interest civic_duty rural_urban elecid meeting meeting_dicho ///
	protest protest_dicho boycott boycott_dicho petition petition_dicho socialm socialm_dicho volunteer volunteer_dicho ///
	contactRep contactRep_dicho donate donate_dicho circulatedInfo circulatedInfo_dicho usedSocialm usedSocialm_dicho ///
	member pes_weights asset eco_well_being income_missing

***************************
********Save***************
***************************

save "sk_prov.dta", replace







***
**************************************************************
**   DATASET : QUEBEC 2022 ELECTION							**
**************************************************************
***

clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"

use "2022 Quebec Election Study v1.dta", clear
	

set more off
numlabel, add


**************************************************************
** 					Generate variables 						**
**************************************************************

*Electoral Participation (0=abstained; 1=voted)
gen turnout=0 if inlist(pes_turnout, 2, 3, 4, 5, 6)
replace turnout=1 if pes_turnout==1

**********
**Bloc 1**
**********

*Age linear
gen age=cps_age_in_years
drop if age < 18
drop if age < 18

*Gender (0=woman; 1=man; 2=other)
gen gender=0 if cps_genderid==2
replace gender=1 if cps_genderid==1
replace gender=2 if cps_genderid==3

gen gender_dicho=0 if cps_genderid==2 // woman
replace gender_dicho=1 if cps_genderid==1 // man


*Sexuality (0=heterosexual; 1=gay or lesbian; 2=bisexual; 3=other)
gen sexuality=0 if pes_orientation==1
replace sexuality=1 if pes_orientation==2
replace sexuality=2 if pes_orientation==3
replace sexuality=3 if pes_orientation==4

gen sexuality_three=sexuality
recode sexuality_three (3=.)

*Education (0=No university; 1=University Degree)
gen education=0 if cps_edu < 9 // No schooling to some university
replace education = 1 if inrange(cps_edu, 9, 11) // Bachelor's degree to Professional degree or doctorate


* Generate the categorical variable from the continuous variable
egen income_cat_num = cut(cps_income), at(0 1 30001 60001 90001 110001 150001 200001 10000000)
recode income_cat_num (0 = 1) (1 = 2) (30001 = 3) (60001 = 4) (90001 = 5) (110001 = 6) (150001 = 7) (200001 = 8)

* Replace category "-99" in pes_income2 with missing
gen income_cat_brut = cps_income2
replace income_cat_brut = . if cps_income2==-99

* Merge the two categorical variables
gen income_cat_merged = .
replace income_cat_merged = income_cat_brut if !missing(income_cat_brut)
replace income_cat_merged = income_cat_num if missing(income_cat_brut) & !missing(income_cat_num)
replace income_cat_merged = . if cps_income2==-99

* Create the 0-1 scaled "income" variable
gen income = (income_cat_merged - 1) / 7

*Income (nominal, missing as a category)
gen income_missing = income_cat_merged
replace income_missing = 9 if cps_income2 == -99


*First Language(s) 
gen langue_nominal = 1 if cps_lang_1 == 1 // Anglo
replace langue_nominal = 2 if cps_lang_2 == 1 // Franco
replace langue_nominal = 3 if cps_lang_1 == 1 & cps_lang_2 == 1 // Bilingual (French & English)
replace langue_nominal = 4 if cps_lang_3 == 1 // Other (allo)


* Language Binary (FR = 1)
gen franco = .
replace franco = 1 if langue_nominal == 2
replace franco = 0 if langue_nominal == 1 | langue_nominal == 3 | langue_nominal == 4


* Generate minovis
gen minovis = .

replace minovis = 0 if pes_race_1 == 1

* Set minovis to 1 if any of the specified variables are 1
foreach var of varlist pes_race_2 pes_race_3 pes_race_4 pes_race_5 pes_race_6 pes_race_7 pes_race_8 pes_race_9 pes_race_10 pes_race_11 pes_race_12 pes_race_13 {
    replace minovis = 1 if `var' == 1
}


* Generate 'Quebec'
gen region = 4


* Generate political interest
gen political_interest = cps_interest_1
replace political_interest = . if political_interest < 0 | political_interest > 10
replace political_interest = (political_interest - 0) / (10 - 0)

* Generate election_interest
gen election_interest = cps_intelection_1
replace election_interest = . if election_interest < 0 | election_interest > 10
replace election_interest = (election_interest - 0) / (10 - 0)


* Generate the 'civic_duty' variable
gen civic_duty = .

* Recode cps_duty values
replace civic_duty = 1 if cps_duty == 1
replace civic_duty = 0 if cps_duty == 2


* Generate the 'rural_urban' variable
gen rural_urban = pes_rural
replace rural_urban = . if rural_urban == 6

*Generate asset variables
gen asset1 = pes_own_1 == 1
gen asset2 = pes_own_2 == 1
gen asset3 = pes_own_3 == 1
gen asset4 = pes_own_4 == 1

*Generate index "asset"
gen asset = asset1 + asset2 + asset3 + asset4
replace asset = . if asset == 0
replace asset = 0 if pes_own_5 == 1
replace asset = asset / 4

*Gen economic well-being 
gen eco_well_being = (income + asset)/2

*Economic well-being (nominal, missing as a category)
gen eco_well_being_missing = eco_well_being
replace eco_well_being_missing = 2 if (pes_own_1==-99 & pes_own_2==-99 & pes_own_3==-99 & pes_own_4==-99 & pes_own_5==-99) | cps_income2==-99


* Generate the string variable 'elecid'
gen elecid = "QC_2022"

* Gen weights
gen pes_weights = pes_weight_general

**********************************
***** INFORMAL PARTCIIPATION *****	
**********************************
	
* Generate meeting (0-1)
gen meeting = .
replace meeting = 0 if pes_participation1_1 == 1
replace meeting = 0.33 if pes_participation1_1 == 2
replace meeting = 0.67 if pes_participation1_1 == 3	
replace meeting = 1 if pes_participation1_1 == 4

gen meeting_dicho = .
replace meeting_dicho = 0 if pes_participation1_1 == 1
replace meeting_dicho = 1 if inlist(pes_participation1_1, 2, 3, 4)

* Generate protest (0-1)
gen protest = .
replace protest = 0 if pes_participation1_2 == 1
replace protest = 0.33 if pes_participation1_2 == 2
replace protest = 0.67 if pes_participation1_2 == 3	
replace protest = 1 if pes_participation1_2 == 4

gen protest_dicho = .
replace protest_dicho = 0 if pes_participation1_2 == 1
replace protest_dicho = 1 if inlist(pes_participation1_2, 2, 3, 4)

* Generate boycott (0-1)
gen boycott = .
replace boycott = 0 if pes_participation1_3 == 1
replace boycott = 0.33 if pes_participation1_3 == 2
replace boycott = 0.67 if pes_participation1_3 == 3	
replace boycott = 1 if pes_participation1_3 == 4

gen boycott_dicho = .
replace boycott_dicho = 0 if pes_participation1_3 == 1
replace boycott_dicho = 1 if inlist(pes_participation1_3, 2, 3, 4)

* Generate petition (0-1)
gen petition = .
replace petition = 0 if pes_participation3_5 == 1
replace petition = 0.33 if pes_participation3_5 == 2
replace petition = 0.67 if pes_participation3_5 == 3	
replace petition = 1 if pes_participation3_5 == 4

gen petition_dicho = .
replace petition_dicho = 0 if pes_participation3_5 == 1
replace petition_dicho = 1 if inlist(pes_participation3_5, 2, 3, 4)

*****pes_partic2****

* Generate socialm (0-1)
gen socialm = .
replace socialm = 0 if pes_participation2_1 == 1
replace socialm = 0.33 if pes_participation2_1 == 2
replace socialm = 0.67 if pes_participation2_1 == 3	
replace socialm = 1 if pes_participation2_1 == 4

gen socialm_dicho = .
replace socialm_dicho = 0 if pes_participation2_1 == 1
replace socialm_dicho = 1 if inlist(pes_participation2_1, 2, 3, 4)

* Generate volunteer (0-1)
gen volunteer = .
replace volunteer = 0 if pes_participation2_2 == 1
replace volunteer = 0.33 if pes_participation2_2 == 2
replace volunteer = 0.67 if pes_participation2_2 == 3	
replace volunteer = 1 if pes_participation2_2 == 4

gen volunteer_dicho = .
replace volunteer_dicho = 0 if pes_participation2_2 == 1
replace volunteer_dicho = 1 if inlist(pes_participation2_2, 2, 3, 4)

* Generate contactRep (0-1)
gen contactRep = .
replace contactRep = 0 if pes_participation2_3 == 1
replace contactRep = 0.33 if pes_participation2_3 == 2
replace contactRep = 0.67 if pes_participation2_3 == 3	
replace contactRep = 1 if pes_participation2_3 == 4

gen contactRep_dicho = .
replace contactRep_dicho = 0 if pes_participation2_3 == 1
replace contactRep_dicho = 1 if inlist(pes_participation2_3, 2, 3, 4)

* Generate donate (0-1)
gen donate = .
replace donate = 0 if pes_participation2_4 == 1
replace donate = 0.33 if pes_participation2_4 == 2
replace donate = 0.67 if pes_participation2_4 == 3	
replace donate = 1 if pes_participation2_4 == 4

gen donate_dicho = .
replace donate_dicho = 0 if pes_participation2_4 == 1
replace donate_dicho = 1 if inlist(pes_participation2_4, 2, 3, 4)		

	
*****pes_partic3****

* Generate circulatedInfo (0-1)
gen circulatedInfo = .
replace circulatedInfo = 0 if pes_participation3_3 == 1
replace circulatedInfo = 0.33 if pes_participation3_3 == 2
replace circulatedInfo = 0.67 if pes_participation3_3 == 3	
replace circulatedInfo = 1 if pes_participation3_3 == 4

gen circulatedInfo_dicho = .
replace circulatedInfo_dicho = 0 if pes_participation3_3 == 1
replace circulatedInfo_dicho = 1 if inlist(pes_participation3_3, 2, 3, 4)

* Generate usedSocialm (0-1)
gen usedSocialm = .
replace usedSocialm = 0 if pes_participation3_4 == 1
replace usedSocialm = 0.33 if pes_participation3_4 == 2
replace usedSocialm = 0.67 if pes_participation3_4 == 3	
replace usedSocialm = 1 if pes_participation3_4 == 4
	
gen usedSocialm_dicho = .
replace usedSocialm_dicho = 0 if pes_participation3_4 == 1
replace usedSocialm_dicho = 1 if inlist(pes_participation3_4, 2, 3, 4)

*****pes_partymember****

* Generate member (1 = yes)
gen member = .
replace member = 1 if pes_partymember == 1
replace member = 0 if inlist(pes_partymember, 2, 3)


******************
****  KEEP  ******
******************

keep turnout age gender gender_dicho sexuality sexuality_three education income income_cat_merged langue_nominal ///
	franco minovis region political_interest election_interest civic_duty rural_urban elecid meeting meeting_dicho ///
	protest protest_dicho boycott boycott_dicho petition petition_dicho socialm socialm_dicho volunteer volunteer_dicho ///
	contactRep contactRep_dicho donate donate_dicho circulatedInfo circulatedInfo_dicho usedSocialm usedSocialm_dicho ///
	member pes_weights asset eco_well_being income_missing

	
***************************
********Save***************
***************************

save "qc_prov.dta", replace





***
**************************************************************
**   DATASET : ONTARIO 2022 ELECTION						**
**************************************************************
***

clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"

use "Ontario 2022 Election Study Dataset v1.dta", clear
	

set more off
numlabel, add


**************************************************************
** 					Generate variables 						**
**************************************************************

*Electoral Participation (0=abstained; 1=voted)
gen turnout=0 if inlist(pes_turnout, 2, 3, 4, 5, 6)
replace turnout=1 if pes_turnout==1

**********
**Bloc 1**
**********

*Age linear
gen age=cps_age_in_years
drop if age < 18

*Gender (0=woman; 1=man; 2=other)
gen gender=0 if cps_genderid==2
replace gender=1 if cps_genderid==1
replace gender=2 if cps_genderid==3

gen gender_dicho=0 if cps_genderid==2 // woman
replace gender_dicho=1 if cps_genderid==1 // man


*Sexuality (0=heterosexual; 1=gay or lesbian; 2=bisexual; 3=other)
gen sexuality=0 if pes_orientation==1
replace sexuality=1 if pes_orientation==2
replace sexuality=2 if pes_orientation==3
replace sexuality=3 if pes_orientation==4

gen sexuality_three=sexuality
recode sexuality_three (3=.)

*Education (0=No university; 1=University Degree)
gen education=0 if cps_edu < 9 // No schooling to some university
replace education = 1 if inrange(cps_edu, 9, 11) // Bachelor's degree to Professional degree or doctorate


* Generate the categorical variable from the continuous variable
egen income_cat_num = cut(cps_income), at(0 1 30001 60001 90001 110001 150001 200001 10000000)
recode income_cat_num (0 = 1) (1 = 2) (30001 = 3) (60001 = 4) (90001 = 5) (110001 = 6) (150001 = 7) (200001 = 8)

* Replace category "-99" in pes_income2 with missing
gen income_cat_brut = cps_income2
replace income_cat_brut = . if cps_income2==-99

* Merge the two categorical variables
gen income_cat_merged = .
replace income_cat_merged = income_cat_brut if !missing(income_cat_brut)
replace income_cat_merged = income_cat_num if missing(income_cat_brut) & !missing(income_cat_num)
replace income_cat_merged = . if cps_income2==-99

* Create the 0-1 scaled "income" variable
gen income = (income_cat_merged - 1) / 7

*Income (nominal, missing as a category)
gen income_missing = income_cat_merged
replace income_missing = 9 if cps_income2 == -99


*First Language(s) 
gen langue_nominal = 1 if cps_lang_1 == 1 // Anglo
replace langue_nominal = 2 if cps_lang_2 == 1 // Franco
replace langue_nominal = 3 if cps_lang_1 == 1 & cps_lang_2 == 1 // Bilingual (French & English)
replace langue_nominal = 4 if cps_lang_3 == 1 // Other (allo)


* Language Binary (FR = 1)
gen franco = .
replace franco = 1 if langue_nominal == 2
replace franco = 0 if langue_nominal == 1 | langue_nominal == 3 | langue_nominal == 4


* Generate minovis
gen minovis = .

replace minovis = 0 if pes_race_1 == 1

* Set minovis to 1 if any of the specified variables are 1
foreach var of varlist pes_race_2 pes_race_3 pes_race_4 pes_race_5 pes_race_6 pes_race_7 pes_race_8 pes_race_9 pes_race_10 pes_race_11 pes_race_12 pes_race_13 {
    replace minovis = 1 if `var' == 1
}


* Generate 'Ontario'
gen region = 3


* Generate political interest
gen political_interest = cps_interest_1
replace political_interest = . if political_interest < 0 | political_interest > 10
replace political_interest = (political_interest - 0) / (10 - 0)

* Generate election_interest
gen election_interest = cps_intelection_1
replace election_interest = . if election_interest < 0 | election_interest > 10
replace election_interest = (election_interest - 0) / (10 - 0)


* Generate the 'civic_duty' variable
gen civic_duty = .

* Recode cps_duty values
replace civic_duty = 1 if cps_duty == 1
replace civic_duty = 0 if cps_duty == 2


* Generate the 'rural_urban' variable
gen rural_urban = pes_rural
replace rural_urban = . if rural_urban == -99

*Generate asset variables
gen asset1 = pes_own_1 == 1
gen asset2 = pes_own_2 == 1
gen asset3 = pes_own_3 == 1
gen asset4 = pes_own_4 == 1

*Generate index "asset"
gen asset = asset1 + asset2 + asset3 + asset4
replace asset = . if asset == 0
replace asset = 0 if pes_own_5 == 1
replace asset = asset / 4

*Gen economic well-being 
gen eco_well_being = (income + asset)/2

*Economic well-being (nominal, missing as a category)
gen eco_well_being_missing = eco_well_being
replace eco_well_being_missing = 2 if (pes_own_1==-99 & pes_own_2==-99 & pes_own_3==-99 & pes_own_4==-99 & pes_own_5==-99) | cps_income2==-99


* Generate the string variable 'elecid'
gen elecid = "ONT_2022"

* Gen weights
gen pes_weights = pes_weight_general

**********************************
***** INFORMAL PARTICIPATION *****	
**********************************
	
* Generate meeting (0-1)
gen meeting = .
replace meeting = 0 if pes_participation1_1 == 1
replace meeting = 0.33 if pes_participation1_1 == 2
replace meeting = 0.67 if pes_participation1_1 == 3	
replace meeting = 1 if pes_participation1_1 == 4

gen meeting_dicho = .
replace meeting_dicho = 0 if pes_participation1_1 == 1
replace meeting_dicho = 1 if inlist(pes_participation1_1, 2, 3, 4)

* Generate protest (0-1)
gen protest = .
replace protest = 0 if pes_participation1_2 == 1
replace protest = 0.33 if pes_participation1_2 == 2
replace protest = 0.67 if pes_participation1_2 == 3	
replace protest = 1 if pes_participation1_2 == 4

gen protest_dicho = .
replace protest_dicho = 0 if pes_participation1_2 == 1
replace protest_dicho = 1 if inlist(pes_participation1_2, 2, 3, 4)

* Generate boycott (0-1)
gen boycott = .
replace boycott = 0 if pes_participation1_3 == 1
replace boycott = 0.33 if pes_participation1_3 == 2
replace boycott = 0.67 if pes_participation1_3 == 3	
replace boycott = 1 if pes_participation1_3 == 4

gen boycott_dicho = .
replace boycott_dicho = 0 if pes_participation1_3 == 1
replace boycott_dicho = 1 if inlist(pes_participation1_3, 2, 3, 4)

* Generate petition (0-1)
gen petition = .
replace petition = 0 if pes_participation3_5 == 1
replace petition = 0.33 if pes_participation3_5 == 2
replace petition = 0.67 if pes_participation3_5 == 3	
replace petition = 1 if pes_participation3_5 == 4

gen petition_dicho = .
replace petition_dicho = 0 if pes_participation3_5 == 1
replace petition_dicho = 1 if inlist(pes_participation3_5, 2, 3, 4)

*****pes_partic2****

* Generate socialm (0-1)
gen socialm = .
replace socialm = 0 if pes_participation2_1 == 1
replace socialm = 0.33 if pes_participation2_1 == 2
replace socialm = 0.67 if pes_participation2_1 == 3	
replace socialm = 1 if pes_participation2_1 == 4

gen socialm_dicho = .
replace socialm_dicho = 0 if pes_participation2_1 == 1
replace socialm_dicho = 1 if inlist(pes_participation2_1, 2, 3, 4)

* Generate volunteer (0-1)
gen volunteer = .
replace volunteer = 0 if pes_participation2_2 == 1
replace volunteer = 0.33 if pes_participation2_2 == 2
replace volunteer = 0.67 if pes_participation2_2 == 3	
replace volunteer = 1 if pes_participation2_2 == 4

gen volunteer_dicho = .
replace volunteer_dicho = 0 if pes_participation2_2 == 1
replace volunteer_dicho = 1 if inlist(pes_participation2_2, 2, 3, 4)

* Generate contactRep (0-1)
gen contactRep = .
replace contactRep = 0 if pes_participation2_3 == 1
replace contactRep = 0.33 if pes_participation2_3 == 2
replace contactRep = 0.67 if pes_participation2_3 == 3	
replace contactRep = 1 if pes_participation2_3 == 4

gen contactRep_dicho = .
replace contactRep_dicho = 0 if pes_participation2_3 == 1
replace contactRep_dicho = 1 if inlist(pes_participation2_3, 2, 3, 4)

* Generate donate (0-1)
gen donate = .
replace donate = 0 if pes_participation2_4 == 1
replace donate = 0.33 if pes_participation2_4 == 2
replace donate = 0.67 if pes_participation2_4 == 3	
replace donate = 1 if pes_participation2_4 == 4
		
gen donate_dicho = .
replace donate_dicho = 0 if pes_participation2_4 == 1
replace donate_dicho = 1 if inlist(pes_participation2_4, 2, 3, 4)
	
*****pes_partic3****

* Generate circulatedInfo (0-1)
gen circulatedInfo = .
replace circulatedInfo = 0 if pes_participation3_3 == 1
replace circulatedInfo = 0.33 if pes_participation3_3 == 2
replace circulatedInfo = 0.67 if pes_participation3_3 == 3	
replace circulatedInfo = 1 if pes_participation3_3 == 4

gen circulatedInfo_dicho = .
replace circulatedInfo_dicho = 0 if pes_participation3_3 == 1
replace circulatedInfo_dicho = 1 if inlist(pes_participation3_3, 2, 3, 4)

* Generate usedSocialm (0-1)
gen usedSocialm = .
replace usedSocialm = 0 if pes_participation3_4 == 1
replace usedSocialm = 0.33 if pes_participation3_4 == 2
replace usedSocialm = 0.67 if pes_participation3_4 == 3	
replace usedSocialm = 1 if pes_participation3_4 == 4

gen usedSocialm_dicho = .
replace usedSocialm_dicho = 0 if pes_participation3_4 == 1
replace usedSocialm_dicho = 1 if inlist(pes_participation3_4, 2, 3, 4)	

*****pes_partymember****

* Generate member (1 = yes)
gen member = .
replace member = 1 if pes_partymember == 1
replace member = 0 if inlist(pes_partymember, 2, 3)


******************
****  KEEP  ******
******************

keep turnout age gender gender_dicho sexuality sexuality_three education income income_cat_merged langue_nominal ///
	franco minovis region political_interest election_interest civic_duty rural_urban elecid meeting meeting_dicho ///
	protest protest_dicho boycott boycott_dicho petition petition_dicho socialm socialm_dicho volunteer volunteer_dicho ///
	contactRep contactRep_dicho donate donate_dicho circulatedInfo circulatedInfo_dicho usedSocialm usedSocialm_dicho ///
	member pes_weights asset eco_well_being income_missing

	
***************************
********Save***************
***************************

save "ont_prov.dta", replace










**************************************************************
**************************************************************
**					  APPEND ALL DATASETS					**
**************************************************************
**************************************************************

*First, we go back to the CES2021 data

clear all

*cd "/Users/daoj2702/Desktop/lgbt informal particpiation/data_lgb_participation/"
cd "C:\Users\melya\Documents\Université\Daoust\LGB_informal participation"


use "ces2021.dta", clear

set more off
numlabel, add
*Second, we append the provincial studies + CES2019
append using "sk_prov.dta" "bc_prov.dta" "ns_prov.dta" ///
				"nl_prov.dta" "nb_prov.dta" "qc_prov.dta" ///
				"ces2019.dta" "ont_prov.dta"

				
				
				
***********************
**Harmonize variables**
***********************				
				
*gen age_cateory
gen age_cat=1 if inrange(age, 18, 29)
replace age_cat=2 if inrange(age, 30, 39)
replace age_cat=3 if inrange(age, 40, 49)
replace age_cat=4 if inrange(age, 50, 59)
replace age_cat=5 if inrange(age, 60, 69)
replace age_cat=6 if inrange(age, 70, 79)
replace age_cat=7 if inrange(age, 80, 100)


* Add generation variable
gen generation = 1 if inrange(age, 18, 26)
replace generation = 2 if inrange(age, 27, 42)
replace generation = 3 if inrange(age, 43, 58)
replace generation = 4 if inrange(age, 59, 75)
replace generation = 5 if inrange(age, 76, 100)


				
***********
***labels**
***********

*Gender
label define gender_lbl 0 "Woman" 1 "Man" 2 "Other"
label values gender gender_lbl
label values gender_dicho gender_lbl

*Sexual orientation
label define sexuality_lbl 0 "Heterosexual" 1 "Gay/Lesbian" 2 "Bisexual" 3 "Other"
label values sexuality sexuality_lbl
label values sexuality_three sexuality_lbl

*Education
label define education_lbl 0 "No university" 1 "University Degree"
label values education education_lbl

*Generation
label define generation_lbl 1 "Generation Z" 2 "Millennials" 3 "Generation X" 4 "Baby Boomers"   5 "Silent Generation"
label values generation generation_lbl

*Age
label define age_cat_label 1 "18-29 years old" 2"30-39 years old" 3 "40-49 years old" 4 "50-59 years old" 5 "60-69 years old" 6 "70-79 years old" 7"80+ years old"
label value age_cat age_cat_label

* First Language(s) 
label define langue_nominal_lbl 1 "Anglophone" 2 "Francophone" 3 "Bilingual (French & English)" 4 "Other"
label values langue_nominal langue_nominal_lbl

* Franco
label define franco_lbl 0 "Other" 1 "Franco"
label values franco franco_lbl

* region labels
label define region_lbl 1 "British Columbia" ///
                        2 "Prairies" ///
                        3 "Ontario" ///
                        4 "Quebec" ///
                        5 "Atlantic"
label values region region_lbl
						
* First Language(s) 
label define minovis_lbl 0 "Non-visible minority" 1 "Visible minority and Indigenous People"
label values langue_nominal langue_nominal_lbl

* Rural-Urban
label define rural_urban_lbl 1 "A rural area or village (less than 1000 people)" ///
							 2 "A small town (more than 1000 people but less than 15K)" ///
							 3 "A middle-sized town (15K-50K people) not attached to a city" ///
							 4 "A suburb of a large town or city" ///
							 5 "A large town or city (more than 50K people)"
label values rural_urban rural_urban_lbl



* Variable labels
label variable age "Age"
label variable age_cat "Age (Categorical)"
label variable generation "Generation"
label variable gender "Gender"
label variable gender_dicho "Gender (dichotomous)"
label variable sexuality "Sexuality"
label variable sexuality_three "Sexuality (three categories)"
label variable education "Education"
label variable income "Income"
label variable langue_nominal "Langue Nominal"
label variable minovis "Visible Minority"
label variable region "Region"
label variable political_interest "Political Interest"
label variable election_interest "Election Interest"
label variable civic_duty "Civic Duty"
label variable rural_urban "Rural/Urban"
label variable elecid "Election ID"
label variable turnout "Electoral Participation"
label variable income_cat_merged "Merged Income Category"
label variable meeting "Participed in Pol. Meeting"
label variable protest "Participated in Protest"
label variable boycott "Participated in Boycott"
label variable petition "Signed Petition"
label variable socialm "Followed any politician (elected of not) on social media"
label variable volunteer "Volunteered for party/candidate"
label variable contactRep "Contacted Representative"
label variable donate "Donated to Political Candidate/Party"
label variable circulatedInfo "Circulated Political information"
label variable usedSocialm "Discussed Politics on Social Medias"
label variable member "Party Membership"
label variable pes_weights "PES Weights"



***********
***Save****
***********

*Save the pooled dataset
save "pooled_cdem_19-22", replace
 
